Python Forum

Full Version: help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
l=['a','b','c'] 
r=[1,2,3] 
e=['a','b','c','d']
n=[]
for i in l:
    for j in r:
        for t in e:
            n.append(i+str(j)+t)
print n
hi, i am trying to do some thing like this - to make all the posibble combintaition of values from all the lists.
the broblem is that i dont know how many list i will have, its depends on the user input.
so is there a way to creates multiple loops without defining then in the inital program?

for i in l:
    for j in r:  
        for t in e:
it should be indent
i think combinations or permutations method in itertools module will help you. try to read documentation and implement them.