How do I make a number of nested loops where depth is a parameter. I am thinking of a function which takes depth as a parameter
def make_nested_loops(depth):
...
And, the result for depth=3 is the following
for i1 in range(10):
for i2 in range(i1 + 1, 10):
for i3 in range(i2 + 1, 10):
# do stuff
So far I've been able to do this using strings building and exec command. But I think there is better and more efficient way to do it.
make_nested_loopssupposed to return? A loop isn't an object, it's a syntactic construct. Perhaps it should take a second argument that is a function to call that receives a tuple(i1, i2, ...)as an argument and is called where#do stuffoccurs.