Remove items from a list
Peter Otten
__peter__ at web.de
Wed Sep 8 13:44:53 EDT 2004
Dan Perl wrote:
> to forget that. Creating another list from the first one by filtering or
> with a list comprehension should be the preferred solution, unless the
> intention is to have this list used in more than one place and have the
> changes reflected in all those places.
Even then there is a less painful solution using slices:
>>> a = b = [1,2,3]
>>> a[:] = [2*i for i in a if i != 2]
>>> a
[2, 6]
>>> b
[2, 6]
Peter
More information about the Python-list
mailing list