I'm trying to modify a loop function that contains over a hundred lines of code.
If I have a loop in python that goes through a list, why does a for item in list:
loop only finish half way through? Shouldn't it keep looping until all items are popped?
For example if I have this list:
l1 = [1,2,3,4,5,6]
for item in l1:
l1.pop(0)
print l1
No matter how many items the list contains, it will only finish when 50% of the list has been popped:
OUTPUT FOR CODE ABOVE:
[2, 3, 4, 5, 6]
[3, 4, 5, 6]
[4, 5, 6]
Process finished with exit code 0
Can I still pop each item in the list without changing the for item in l1:
loop?