Trying to find all the combinations of values inside N lists
I am trying to compare all combinations of the values in N lists. Each list is identical holding values 1 through 9 in order. I am having a very hard time figuring out how to code this because I cannot create N nested loops beforehand. N is user defined and won't be known until run time. The place I always get stuck on is trying to iterate through every possible combination of values in an arbitrary number of lists using a fixed number of loops.
Any suggestions? I've been trying for an hour now to figure this out. I'm sure it is something simple I开发者_如何转开发 am missing.
import itertools
for combo in itertools.product(xrange(1, 10), repeat=N):
...
精彩评论