I have a list of lists and need to extract each item; to ultimately write their Cartesian product.
from itertools import product
b = {}
a = [[1, 2], [3, 4], ['a', 'b']]
for i, v in enumerate(a):
b[i] = v
#These don't work because we are feeding a single list to product
print list(product(x for x in a)) # [([1, 2],), ([3, 4],), (['a', 'b'],)]
print list(product(b.values())) # [([1, 2],), ([3, 4],), (['a', 'b'],)]
The product
works correctly if I am able to get this :
print list(product([1, 2], [3, 4], ['a', 'b']))
[(1, 3, 'a'), (1, 3, 'b'), (1, 4, 'a'), (1, 4, 'b'), (2, 3, 'a'), (2, 3, 'b'), (2, 4, 'a'), (2, 4, 'b')]