In my Python 2.7.2 IDLE interpreter:
>>> mylist = [1, 2, 3, 4, 5] >>> for item in mylist: mylist.remove(item) >>> mylist [2,
That's because you're modifying the list while iterating over it, iterate over a shallow copy instead:
>>> mylist = [1, 2, 3, 4, 5] >>> for item in mylist[:]: #use mylist[:] or list(mylist) mylist.remove(item) ... >>> mylist []