In my Python 2.7.2 IDLE interpreter:
>>> mylist = [1, 2, 3, 4, 5] >>> for item in mylist: mylist.remove(item) >>> mylist [2,
Problem is that you are altering the list while iterating on it. Use a list comprehension instead:
mylist = [1, 2, 3, 4, 5] mylist = [x for x in mylist if condition(x)]