Read vertically all the values of all the possible combinations of an unknown number of lists with different sizes in Python
Question: I want implement a function that combines **vertically** all the elements of
an **unknown number of lists** in Python. Each list has a **different size**.
E.g., this is the list of list and each row is a list:

    
    
    A0, A1
    B0
    C0, C1, C2
    

Then I would like to print

    
    
    A0, B0, C0
    A0, B0, C1
    A0, B0, C2
    A1, B0, C0
    A1, B0, C1
    A1, B0, C2
    

Note that in the example there are 3 lists but they could also more or less,
not necessary 3. My problem is that I don't have idea how to solve it. I tough
to implement a recursive method, in which if some condition is satisfied then
print the value, else call recursively the function. Here the pseudo-code:

    
    
    def printVertically(my_list_of_list, level, index):
        if SOME_CONDITION:
            print str(my_list_of_list[index])
    
        else:
            for i in range (0, int(len(my_list_of_list[index]))):
                printVertically(my_list_of_list, level-1, index)
    

Here the main code:

    
    
    list_zero = []
    list_zero.append("A0")
    list_zero.append("B0")
    list_zero.append("C0")
    
    list_one = []
    list_one.append("A1")
    
    list_two = []
    list_two.append("A2")
    list_two.append("B2")
    
    list_three = []
    list_three.append("A3")
    list_three.append("B3")
    list_three.append("C3")
    list_three.append("D3")
    
    
    my_list_of_list = []
    my_list_of_list.append(list_zero)
    my_list_of_list.append(list_one)
    my_list_of_list.append(list_two)
    my_list_of_list.append(list_three)
    
    
    level=int(len(my_list_of_list))
    index=0
    printVertically(my_list_of_list, level, index)
    

_level_ is the length of the list of list and _index_ should represent the
index of a specific list used when I want to print a specific element. Well,
no idea how to proceed. Any hint?

I have searched but in all solutions, people knew the number of lists or the
number of elements in each list, like these links:

[Link 1](http://stackoverflow.com/questions/34143934/using-zip-to-read-a-file-
vertically-and-search-through-the-zipped-list)

[Link 2](http://stackoverflow.com/questions/15707433/reading-files-as-both-
vertical-lists-and-horizental-listspython-3-2)

[Link 3](http://stackoverflow.com/questions/2990003/how-can-i-find-all-the-
possible-combinations-of-a-list-of-lists-in-python)


Answer: I believe that what you want here is the cross-product of the various sets.
You can do this with Python's **itertools.product** method. Documentation is
[here](https://docs.python.org/2/library/itertools.html#itertools.product).
Something like:

    
    
    import itertools
    a_list = ["A0", "A1"]
    b_list = ["B0"]
    c_list = ["C0", "C1", "C2"]
    for combo in itertools.product(a_list, b_list, c_list):
        print combo
    

Output:

    
    
    ('A0', 'B0', 'C0')
    ('A0', 'B0', 'C1')
    ('A0', 'B0', 'C2')
    ('A1', 'B0', 'C0')
    ('A1', 'B0', 'C1')
    ('A1', 'B0', 'C2')
    

Does that get you moving?

* * *

Example with one overarching list:

    
    
    my_list_list = [a_list, b_list, c_list]
    for combo in itertools.product(*my_list_list):
        print combo
    

... and we get the same output

