Function with varying number of For Loops (python)

I’m not clear why you can’t use the product of the bounds and do

for x in range(y exp n)

where n is the # of loops…. You say y exp n will be huge, but I’m sure python can handle it.

However, that being said, what about some sort of recursive algorithm?

def loop_rec(y, n):
    if n >= 1:
        for x in range(y):
            loop_rec(y, n - 1)
    else:
       whatever()

Leave a Comment