How to del item of a list in loop?

John Machin sjmachin at
Sat Jan 15 19:34:00 EST 2005

Fredrik Lundh wrote:
>     lst = [i for i in lst if i != 2]
> (if you have 2.4, try replacing [] with () and see what happens)

The result is a generator with a name ("lst") that's rather misleading
in the context. Achieving the same result as the list comprehension, by
doing lst = list(i for ... etc etc), appears to be slower.

More information about the Python-list mailing list