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

Hrvoje Niksic hniksic at xemacs.org
Wed Jan 30 14:52:47 CET 2008


Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:

> Quadratic time!! Yowch!!  Back to the future:
>
> def rocket_science(xs):
>    for x in xs:
>       if x != 99:
>          yield x
>
> a[:] = list(rocket_science(a))

I call "useless use of list"!

a[:] = rocket_science(a)

:-)



More information about the Python-list mailing list