def foo():
l = [0, 0, 0]
for i in range(3):
l[i] = random.random()
for j in l:
if j > 0.5:
for i in range(3):
l[i] = random.random()
foo()
else:
print("Returning...")
return None
return None
My recursive function modifies a list l. The recursive call is nested while iterating on l. The problem is that when returning from a nested call, the list on which the for loop is iterating will be a different one (because l is overwritten during the nested call).
Example: l = [0.7, 0.5, ...] at the first execution of foo(), then j = 0.7; let us assume that l becomes
l = [0.3, 0.86, ...] in the first nested call of foo(); when foo() returns, I need j to take the value 0.5, but that does not happen because l has been overwritten in the meantime.
So, how can I use (modify) the list l in my recursive function and, at the same time, make sure that once an iteration begins on l, it is done on the same list until its end?
countThe edit link is just below the post text.returnalmost every single day