1

I have a var l, and it contains a n number of tuples or ranges, chosen how I like, and I want to travel/loop through it in all the ranges, like this:

l = (range(4), range(8))
for i in l[0]:
    for j in l[1]:
        #work with i and j

l = (range(4), range(8), range(1), range(88))
for i in l[0]:
    for j in l[1]:
        for u in l[2]:
            for y in l[3]:
                #work with i, j, u and y

Another way:

l = (range(n1), range(n2), ...)
for k in Something(l):
    #where k[0] is in n1, k[1] is in n2 .....

The last generalization doesn't need to be in that form, it would be ideal if it can be in a for loop, and I really want to avoid a recursion function.

The code needs to work in Python 3 and Python 2.

Thx.

Ryan
  • 2,167
  • 2
  • 28
  • 33
Latot
  • 155
  • 8

0 Answers0