I want to create a code that can iterate over a dynamic number (N) of nested loops each with different range. For example:
N=3
ranges=[[-3, -2, -1, 0, 1, 2, 3],
[-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5],
[-3, -2, -1, 0, 1, 2, 3]]
for x in ranges[0]:
for y in ranges[1]:
for z in range[2]:
variable=[x, y, z]
Im new to python. As I went over similar questions posted here I have the understanding that this can be done with recursion or itertools. However, none of the answers posted solve this problem for a different range at each level. The closest posted question similar to mine was Variable number of nested for loops with fixed range . However, the answer posted by user633183 is coded in python 3.X and I am coding in python 2.7 so I couldn't implement it as some of its code does not work on python 2.7. Can you please help me to code this problem. Thanks!