Given two lists in Python
a = [1, 2, 3]
b = [4, 5, 6]
We can use c=list(itertools.product(a,b))
to generate all possible permutations, this will output
[(1, 4), (1, 5), (1, 6), (2, 4), (2, 5), (2, 6), (3, 4), (3, 5), (3, 6)]
Now we need to generate these sets from c
[[(1,4),(2,5),(3,6)],
[(1,4),(2,6),(3,5)],
[(1,5),(2,4),(3,6)],
[(1,5),(2,6),(3,4)],
[(1,6),(2,4),(3,5)],
[(1,6),(2,5),(3,4)]]
Each list here is a possible pairing of all elements in a
with b
. The number of pairings is the number of possible permutations taking two at a time. The solution needs work for any number of elements in a
and b
.