def kbits(n, k):
result =
for bits in itertools.combinations(range(n), k):
s = ['0'] * n
for bit in bits:
s[bit] = '1'
result.append(''.join(s))
return result
You do realize the answer will have (1_000_000 choose k) values in the result, right? Even if you could generate a variation in 1 ns, it would take longer than the age of the universe to do anything above k = 4.
If you use a more realistic n, you can go with one of the primitive types (e.g. u128), or a bitvec.