Removing from a List in Place

Gregory Piñero gregpinero at gmail.com
Tue Sep 5 16:51:05 EDT 2006


I'm going to assume that it's supposed to work like this, but could
someone tell me the reasoning behind it?  I.E. why is 3 skipped?

>>> alist=[1,2,3]
>>> for item in alist:
... 	print item
... 	if item==2:
... 		alist.remove(item)
... 		
1
2
>>>

Bonus Question:
Can we make this behave more intuitiviely in Python 3000?

-Greg


-- 
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com)



More information about the Python-list mailing list