Removal of element from list while traversing causes the next element to be skipped

Joe Riopel goon12 at gmail.com
Tue Jan 29 21:12:46 EST 2008


On Jan 29, 2008 9:23 AM, attn.steven.kuo at gmail.com
<attn.steven.kuo at gmail.com> wrote:
> If you're going to delete elements from
> a list while iterating over it, then do
> it in reverse order:

how about
>>> li = [1,2,3,4,5]
>>> filter(lambda x: x != 3, li)
[1, 2, 4, 5]
>>>



More information about the Python-list mailing list