Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help
#1
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
Reply
#2
i think combinations or permutations method in itertools module will help you. try to read documentation and implement them.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020