iterating through lists to delete elements

Peter Hansen peter at engcorp.com
Fri Aug 10 01:34:07 CEST 2001


(edited for conventional quoting style)

Lance.Ellinghaus at eConnections.com wrote:
> 
> Joe Knapka wrote:
> > So it seems that (shudder) There's More Than One
> > Way To Do It. Isn't there supposed to be one (obvious) 
> > way?
> 
> As you will learn through the years as a programmer, 
> there is normally more than one way to do anything in 
> software. It becomes a personal choice based on previous 
> programming and personal philosophy.

Joe was referring, of course, to one of Python's credos,
copied from one of the PSU's secret files by Tim Peters
(see http://www.pauahtun.org/TYPython/PythonWay.html) which
claims "There should be one -- and preferably only one --
obvious way to do it."  

(It is commonly presumed he was not referring to sex...)

(Joe, I think the "make a copy and iterate over it 
while removing from the original" might be the 
"obvious" way to a beginner, while the filter
technique would become obvious to a more advanced
programmer.  More likely, this is one of the few
cases where the "preferably only one" wish fails.)

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list