I am trying to use Python-2.7 to play around with "Randomization Distributions", but can't find the right itertool
to do the job.
Imagine I have the list ['A', 'B', 'B']
Using itertools.permuations()
will give me the following:
('A', 'B', 'B')
('A', 'B', 'B')
('B', 'A', 'B')
('B', 'B', 'A')
('B', 'A', 'B')
('B', 'B', 'A')
When what I really want is the permutations without the duplicates:
('A', 'B', 'B')
('B', 'A', 'B')
('B', 'B', 'A')
Of course I could filter, but on real-world size datasets, you get a combinatorial explosion with the first method, whereas as the second isn't so bad.
fact(len(A) + len(B))
versus fact(len(A) + len(B)) / (fact(len(A) * fact(len(B)))
If len(A) = 6
and len(B) = 5
, that's 399,916,800
vs. 462
Is there a tool for this?
Sidenote: if someone can come up with a more descriptive title so that this question is more searchable to others, I am open to suggestions. Please leave a comment.