list remove

Skip Montanaro skip at pobox.com
Tue Oct 2 13:21:44 EDT 2001


    Oleg>    NEVER, I said NEVER modify the list while running through it!

Never say "never".  ;-)

This works just fine:

    >>> foo = [1,2,3,4,5]
    >>> for i in range(len(foo)-1,-1,-1):
    ...   del foo[i]
    ... 
    >>> foo
    []

-- 
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/




More information about the Python-list mailing list