Deleting from a list while iterating
Fredrik Lundh
fredrik at pythonware.com
Sun Dec 3 11:03:24 EST 2006
Marc 'BlackJack' Rintsch wrote:
> No need to iterate twice over the `items`. The two other approaches you
> gave are just needed if it's important that the elements are deleted "in
> place", i.e. that you don't rebind `items` to a new object.
and even when you do, that can often be written as, e.g:
items[:] = (i for i in items if not i < 0.5)
</F>
More information about the Python-list
mailing list