list.pop([i]) and list.remove(x) w/ for loops
David White
dwhite2 at blue.seas.upenn.edu
Wed Jun 28 14:15:02 EDT 2000
I was getting some unexpected behavior when using list.remove(x), wondering if
someone can tell me what's going on.
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. My code looks like this:
for o in olist:
if (o.type == a):
olist.remove(o)
Now for some reason I get a left over a object that wasn't removed. Anyone
know why? Using python 1.5.2.
thanks,
david
More information about the Python-list
mailing list