tags:

views:

45

answers:

1

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.

+4  A: 
import itertools
for combo in itertools.product(xrange(1, 10), repeat=N):
  ...
Matthew Flaschen
You, sir, are awesome.
Andrew