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

Paul Rubin http
Wed Jan 30 02:09:56 EST 2008


Santiago  Romero <sromero at gmail.com> writes:
> > >>> li = [1,2,3,4,5]
> > >>> filter(lambda x: x != 3, li)
> > [1, 2, 4, 5]
> 
>  I haven't measured it, but this should be the fast solution in all
> the thread ...

li.remove(3) is probably faster.



More information about the Python-list mailing list