iterating through lists to delete elements

Erik Max Francis max at
Thu Aug 9 18:19:16 CEST 2001

Mark Robinson wrote:

> Can anyone advise me the best way to iterate through a list and
> deleting
> elements that don't meet a certain criteria.

Use filter to make a new list, and then replace the original list with
the filtered one.

Modifying a list in place while you're iterating over it isn't a very
good idea.

 Erik Max Francis / max at /
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ All the people in his neighborhood turn around and get mad and sing
\__/ Public Enemy
    Alcyone Systems' CatCam /
 What do your pets do all day while you're at work?  Find out.

More information about the Python-list mailing list