lambda n:[k/n for k in range(n*n)if k/n*k%n==1]
Try it online!
Background
Consider the ring (Zn, +n, ·n). While this ring is usually defined using residue classes modulo n, it can also be thought of as the set Zn = {0, ..., n - 1}, where the addition and multiplication operators are defined by a +n b = (a + b) % n and a ·n b = a · b % n, where +, ·, and % denote the usual addition, multiplication, and modulo operators over the integers.
Two elements a and b of Zn are called mutual multiplicative inverses modulo n if a ·n b = 1 % n. Note that 1 % n = 1 whenever n > 1.
Fix n > 1 and let a be a coprime of n in Zn. If a ·n x = a ·n y for two elements x and y of Zn, we have that a · x % n = a · y % n. This implies that a · (x - y) % n = a · x % n - a · y % n = 0, and we follow that n | a · (x - y), i.e., n divides a · (x - y) evenly. Since n shares no prime divisors with a, this means that n | x - y. Finally, because -n < x - y < n, we conclude that x == y. This shows that the products a ·n 0, …, a ·n (n - 1) are all different elements of Zn. Since Zn has exactly n elements, one (and exactly one) of those products must be equal to 1, i.e., there is a unique b in Zn such that a ·n b = 1.
Conversely, fix n > 1 and let a be an element of Zn that is not coprime to n. In this case, there is a prime p such that p | a and p | n. If a admitted a multiplicative inverse modulo n (let's all it b), we'd have that a ·n b = 1, meaning that a · b % n = 1 and, therefore, (a · b - 1) % n = a · b % n - 1 = 0, so n | a · b - 1. Since p | a, we follow that p | a · b. On the other hand, since p | n, we also follow that p | a · b - 1. This way, p | (a · b) - (a · b - 1) = 1, which contradicts the assumption that p is a prime number.
This proves that the following statements are equivalent when n > 1.
How it works
For each pair of integers a and b in Zn, the integer k := a · n + b is a unique; in fact, a and b are quotient and remainder of k divided by n, i.e., given k, we can recover a = k / n and b = k % n, where / denotes integer division. Finally, since a ≤ n - 1 and b ≤ n - 1, k is an element of Zn2; in fact, k ≤ (n - 1) · n + (n - 1) = n2 - 1.
As noted above, if a and n are coprime, there will be a unique b such that a · b % n = 1, i.e., there will be a unique k such that k / n = a and k / n · k % n = (k / n) · (k % n) % n = 1, so the generated list will contain a exactly once.
Conversely, if a and n are not coprime, the condition k / n · k % n = 1 will be false for all values of k such that a = k / n, so the generated list will not contain a.
This proves that the list the lambda returns will contain all of n's coprimes in Zn exactly once.
1\n3\n) count as valid output? – devRicher 6 hours ago