I'm trying to generate all the possible permutations of a string like "0000011111" or "000 11 2222 333". I tried using permutations from itertools on "0000011111" like so:
from itertools import permutations
basestring = "0"*5 +"1"*5
perms = [''.join(p) for p in permutations(basestring)]
print(len(perms), perms)
print(len(set(perms)), set(perms))
But the list perms had 3 million entries when there are only 10 C 5 = 252 permutations.
Is there a built in tool I can use that is better at handling permutations of strings with many repeated characters?
Otherwise how is this algorithm for generating the permutations (for "0000 1111 222")?
Start with 2 characters "0000 1111"
Move right most 0 over one "0001 0111" and add it to the list
Continue moving it to the end "0001 1011" -> "0001 1101" -> "0001 1110"
Now move the next 0 over one "0010 0111" -> "0010 1011"
...
Until you get to "1111 0000".
Then for each of the strings generated, repeat the process with 2's.
222 xxxx xxxx -> 22x 2xxx xxxx -> 22x x2xx xxx...
Or am I better off just doing set(perms) to get rid of the repeats? (I need to permute 20 character lists with 3-5 characters where itertools permutations would give me 10e18 strings)
I've been programming casually for 3 years, but only know as much as someone with 1 semester of a programming class.