I am wondering about the loop behavior when I am popping each element but that could apply to any modifications on an iterrables.
Let's imagine this:
l = ["elem1", "elem2", "elem3", "elem4"]
for i, elem in enumerate(l):
l.pop(i)
It is simple but i am wondering: does python keep a unmodified instance of l at each loop iteration or does it update l ? I could loop over a l.copy()
but in that case i have an IndexError
.
I know that i could simply solve the issue of removing elem in list one by one but here i am trying to understand the behavior.