list remove
Terry Reedy
tjreedy at home.com
Tue Oct 2 13:56:16 EDT 2001
> 0 has the section more on lists where it gives the function
remove(x). I am
> trying to use this function to delete elements out of my list, but
it only
> deletes every other list.
>
> >>>foo = [1, 2, 3, 4, 5]
> >>>for bar in foo:
> ... foo.remove(bar)
>
> >>>foo
> [2, 4]
Besides the other answers ...
foo [] #bind 'foo' to empty list
foo[:] # delete in place
To selectively delete multiple items, use filter().
Terry J. Reedy
More information about the Python-list
mailing list