How to del item of a list in loop?

John Machin sjmachin at lexicon.net
Sat Jan 15 21:22:40 EST 2005


Nick Coghlan wrote:
> I think this is about the best you can do for an in-place version:
>    for i, x in enumerate(reversed(lst)):
>      if x == 2:
>        del lst[-i]
I think del lst[-i-1] might be functionally better.




More information about the Python-list mailing list