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: