I have an array [1, 1, 2, 3, 3, 3, 0, 0, 0, 0, 0]
. I want to generate all permutations under considerations of symmetry/repetition (i.e. for a smaller example: [1, 1]
has only one permutation, not two for exchanging the 1
s.) Enumerating all permutations with itertools (see code below) is not efficient, especially since I want to go to larger sets.
from itertools import permutations
p = permutations([1, 1, 2, 3, 3, 3, 0, 0, 0, 0, 0])
j = 0
for i in list(p):
print(i)
j += 1
# reduce all permutations e.g. with set().
Is there an elegant way of enumerating all combinations? How can I implement it in an efficient way (may largest case has about 100 elements in the array)? Thanks for the help.