I have a list of lists as such, the no. of inner list is unknown:
>>> x = [1,2,3]
>>> y = [4,5,6,7]
>>> z = [8]
>>> lol = [x,y,z]
I need to get a combinations from each item within the inner list in the order of the lol lists, I have been doing it as such to get the desired output:
>>> for i in x:
...     for j in y:
...             for k in z:
...                     print [i,j,k]
... 
[1, 4, 8]
[1, 5, 8]
[1, 6, 8]
[1, 7, 8]
[2, 4, 8]
[2, 5, 8]
[2, 6, 8]
[2, 7, 8]
[3, 4, 8]
[3, 5, 8]
[3, 6, 8]
[3, 7, 8]
What is the pythonic way to do the above? Is there a itertools function for this?
I've tried itertools.product but i didn't get the desired output:
>>> from itertools import product
>>> for i in product(lol):
...     print i
... 
([1, 2, 3],)
([4, 5, 6, 7],)
([8],)
 
     
     
     
    