Create list of list in python
Question: Suppose I have three lists

    
    
    [-1,0,1,2]
    [0,1]
    [a,b,c]
    

I would like to obtain a list as

    
    
    [-1,0,a]
    [-1,0,b]
    [-1,0,c]
    
    [-1,1,a]
    [-1,1,b]
    [-1,1,c]
    
    [0,0,a]
    [0,0,b]
    [0,0,c]
    ...
    

How to write a python function to achieve this goal?


Answer: You can use
[`itertools.product()`](https://docs.python.org/2/library/itertools.html#itertools.product):

    
    
    from itertools import product
    from pprint import pprint
    
    l = [[-1, 0, 1, 2], [0, 1], ['a', 'b', 'c']]
    result = list(product(*l))
    pprint(result)
    

Result:

    
    
    [(-1, 0, 'a'),
     (-1, 0, 'b'),
     (-1, 0, 'c'),
     (-1, 1, 'a'),
     (-1, 1, 'b'),
     (-1, 1, 'c'),
     (0, 0, 'a'),
     (0, 0, 'b'),
     (0, 0, 'c'),
     (0, 1, 'a'),
     (0, 1, 'b'),
     (0, 1, 'c'),
     (1, 0, 'a'),
     (1, 0, 'b'),
     (1, 0, 'c'),
     (1, 1, 'a'),
     (1, 1, 'b'),
     (1, 1, 'c'),
     (2, 0, 'a'),
     (2, 0, 'b'),
     (2, 0, 'c'),
     (2, 1, 'a'),
     (2, 1, 'b'),
     (2, 1, 'c')]
    

