When I use List.pop inside a for loop that uses enumerate, the process terminates before getting to the end of the list. How do I get around having pop cut short the process?
I've checked that if I write the loop using pop but without enumerate, then it works as expected. Likewise, if I remove pop and use enumerate to do something else, it also works as expected.
Here is the code:
x=[0,2,4,6,8,10]
for i in enumerate(x):
x.pop(0)
print(x)
I expect to have the following printed:
[2,4,6,8,10]
[4,6,8,10]
[6,8,10]
[8,10]
[10]
[]
Instead, I receive
[2,4,6,8,10]
[4,6,8,10]
[6,8,10]
If I run it again then I receive
[8,10]
[10]
and if I run it again I receive
[]