list remove
Chris Barker
chrishbarker at home.net
Tue Oct 2 18:21:32 EDT 2001
Skip Montanaro wrote:
> Oleg> NEVER, I said NEVER modify the list while running through it!
>
> Never say "never". ;-)
> >>> foo = [1,2,3,4,5]
> >>> for i in range(len(foo)-1,-1,-1):
> ... del foo[i]
> ...
> >>> foo
> []
But this doesn't modify the list you are running through, it modifies
foo, while you are running through the list generated by the range().
-Chris
--
Christopher Barker,
Ph.D.
ChrisHBarker at home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------
More information about the Python-list
mailing list