list.pop([i]) and list.remove(x) w/ for loops
Frédéric van der Plancke
fplancke at my-deja.com
Wed Jun 28 15:23:46 EDT 2000
In article <8jdfb6$ugh$1 at netnews.upenn.edu>,
dwhite2 at blue.seas.upenn.edu (David White) wrote:
> I have a list of 2 kinds of objects, such as [a, a, b, b, a, b].
> I wan't to delete all the a objects out of the list while
> preserving the order of the b objects.
You can also use the 'filter' builtin function:
def f(o):
return o.type != a
olist = filter(f, olist)
# filter(f, olist) returns a copy of olist with only the
# items o such that f(o) returns a true value
or shorter:
olist = filter(lambda o: o.type != a, olist)
--
Frederic van der Plancke
e-mail address: reverse and add dots etc. to:
<com writeme vdplancke frederic>
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list