With
import itertools
l1 = [1,2,3,4]
l2 = [1,2,3,4]
x = itertools.product(l1, l2)
print(list(x))
I get the 16 possible individual combinations of the lists l1 and l2, [(1,1), (1,2), ... ]
etc. Is there a way to also get combinations that 'connect' the lists in multiple ways? For example, I could have the following combinations [(1,1), (2,3)]
, [(1,3), (2,4), (3,2)]
, and [(1,2), (2,4), (3,3), (4, 1)]
.
Any help would be greatly appreciated.