1

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.

Michael Molter
  • 1,296
  • 2
  • 14
  • 37
  • I was worried I had missed a duplicate. As mentioned, its very difficult to find a descriptive title for this problem and similarly meaningful search terms. Here, however, is a very good solution http://stackoverflow.com/questions/12836385/how-can-i-interleave-or-create-unique-permutations-of-two-stings-without-recurs/12837695#12837695 – Michael Molter Nov 13 '16 at 03:02

0 Answers0