Hi,
python makes this happen.
Because when you do out = f(inp), it first gets the inp, then evaluates f(inp), then delete the content of out then associate the result to out.
As you can see, the deletion here happens after the new value has been computed.
A simple way around this is to move your loop content inside a function so that the whole body of the function goes out of scope when you exit the function and before you exit the current iteration of the loop.