List problem
Erik Max Francis
max at alcyone.com
Fri Oct 29 18:23:22 EDT 2004
Cliff Wells wrote:
> Another approach (that doesn't require creating a copy of the list) is
> to iterate backwards over it:
Another way would be to not iterate over the list per se, but rather use
indices into the list and increment them when you delete an item, or
don't when you don't, thereby going over the entire list:
i = 0
while i < len(aList):
if dontWant(aList[i]):
del aList[i]
else:
i += 1
--
__ Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
/ \ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
\__/ I am not afraid / To be a lone Bohemian
-- Lamya
More information about the Python-list
mailing list