Am trying to swap items between multiple lists and I wanted to know if there is any method to generate combinations between multiple list of different size?
For example, I have this 3 lists:
a = [(0, 0), (1, 0), (2, 0)]
b = [(0, 2), (1, 2), (2, 2)]
c = [(0, 3), (1, 3)]
Expected result:
a : [(0, 3), (0, 2), (0, 0)]
b : [(1, 3), (1, 2), (1, 0)]
c : [(2, 2), (2, 0)]
a : [(0, 3), (0, 2), (0, 0)]
b : [(1, 3), (1, 2), (2, 0)]
c : [(2, 2), (1, 0)]
...
a : [(0, 3), (0, 2)]
b : [(1, 3), (1, 2), (0, 0)]
c : [(2, 2), (2, 0), (1, 0)]
I found this code here (python combinations of multiple list):
import itertools as it
import numpy as np
a = [(0, 0), (1, 0), (2, 0)]
b = [(0, 2), (1, 2), (2, 2)]
c = [(0, 3), (1, 3)]
def combination(first, *rest):
for i in it.product([first], *(it.permutations(j) for j in rest)):
yield tuple(zip(*i))
for i in combination(c, b, a):
print("a :", list(i[0]))
print("b :", list(i[1]))
print("c :", list(i[2]))
It works perfectly fine if the list are the same size.