Say I had the following nested list in Python:
lst = [[0, 1, 2],
[3],
[4, 5]]
I want to create a list of all the possible number combinations of length lst
where each list within lst
is sampled only once for each combination. So the output for this example would be:
[[0,3,4], [0,3,5], [1,3,4], [1,3,5], [2,3,4], [2,3,5]]
I could do:
[[x0,x1,x2] for x0 in lst[0] for x1 in lst[1] for x2 in lst[2]]
which returns the correct answer here, but in my case I don't know how many lists are nested in lst
so how would I do this efficiently if the number of lists is variable?