Using itertools
and permutation()
to get all unique combinations of two lists is easy. For instance, if I had:
['a', 'b']
[1, 2]
I could easily get:
[
[('a',1),('b',2)],
[('a',2),('b',1)]
]
However, what I really want is to allow duplicate pairings. Each item in the larger list will be unique, but the number of combinations would be exponential, since the same item in the first list could get assigned to multiple items in the second list. So for the two lists above, I would get:
[
[('a',1),('a',2)],
[('a',1),('b',2)],
[('b',1),('a',2)]
[('b',1),('b',2)]
]
If I had three items in each of the two lists, I would end up with 27 results. What would be the best approach to this?