If I have 3 lists - 'a', 'b', and 'c', and I want to find every possible combination which consists of one value from each loop, that's easy.
a = [1,2,3]
b = [4,5,6]
c = [7,8,9]
def combo_finder(a,b,c):
result = []
for x in a:
for y in b:
for z in c:
result.append([x,y,z])
return result
Or to write it so it can take a single argument, like this:
l = [a,b,c]
def combo_finder(l):
result = []
for x in l[0]:
for y in l[1]:
for z in l[2]:
result.append([x,y,z])
return result
But say i need it to accomodate an argument l that contains n number of lists inside? How can I create nested for loops on demand? I've tried writing recursively, but I seem to keep running into infinite recusion that way.