Change list while looping


Probably not a good idea...


examples/advanced/change_list_on_the_fly.py
numbers = [1, 2, 3, 4]
for n in numbers:
    print(n)
    if n == 2:
        numbers.remove(2)


print(numbers)

1
2
4
[1, 3, 4]

Note, the loop only iterated 3 times, and it skipped value 3