probably basic, but couldn’t find it in any other question.
I tried:
print ["".join(seq) for seq in itertools.permutations("00011")]
but got lots of duplications, seems like itertools doesn’t understand all zeroes and all ones are the same…
what am I missing?
EDIT:
oops. Thanks to Gareth I’ve found out this question is a dup of: permutations with unique values.
Not closing it as I think my phrasing of the question is clearer.
returns a list of 10 positions where the two ones can be within the five-digits (others are zero):
For your case with 2 ones and 13 zeros, use this:
which returns a list of 105 positions. And it is much faster than your original solution.
Now the function:
and this needs 14.4µs.
returning 105 elements needs 134µs.