This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author petri.lehtinen
Recipients Eklutna, petri.lehtinen
Date 2012-06-28.05:06:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1340859987.88.0.0830426556627.issue15214@psf.upfronthosting.co.za>
In-reply-to
Content
This happens because you modify the list while iterating over it, which makes the loop not work as you expect. Essentially, when you remove the item that's currently being pointed to, the loop skips over the next item.

An idiomatic way to remove items from a list is to use a list comprehension to create a new list without the unwanted items:

item_list = ["apple", "bananna", "blueberry", "coconut"]
new_list = [item for item in item_list if not item.startswith('b')]
History
Date User Action Args
2012-06-28 05:06:28petri.lehtinensetrecipients: + petri.lehtinen, Eklutna
2012-06-28 05:06:27petri.lehtinensetmessageid: <1340859987.88.0.0830426556627.issue15214@psf.upfronthosting.co.za>
2012-06-28 05:06:27petri.lehtinenlinkissue15214 messages
2012-06-28 05:06:26petri.lehtinencreate