You can use itertools.product() to replace nested FOR loops if they are not interconnected.
for x, y in product(range(20), range(17)): ....
The question is there a way to do the same for hierarchical nested FOR loop ..f.e. lets say I have list-of-list :
for level2 in LoL :
for level3 in level2 :
for level4 in level3 :
.....
t1, t2,..,tn = levelM
The LoL structure could be something like this, just an example :
[[[1, 9], [1, 6], [1, 8], [1, 6], [1, 2]],
[[5, 8], [5, 11], [5, 14], [5, 6], [5, 11]],
[[7, 12], [7, 13], [7, 10], [7, 9], [7, 12]],
[[22, 25], [22, 30], [22, 25], [22, 26], [22, 26]],
[[55, 57], [55, 55], [55, 55], [55, 56], [55, 61]]]
the output does not matter, I was wondering if there is shortcut function/structure like the product()
The only other way I see is recursion, but this is more complex.
the product() hides the structure ... now that @RaySteam said it .. probably would be function that flattens it !!! up to the last level, so it returns list of tuples, because that is what you normally do in a normal scenario ...i.e. does something with the data..in a loop manner