list.without()?

Magnus L. Hetland mlh at vier.idi.ntnu.no
Tue Nov 16 04:20:15 EST 1999


"Mike Fletcher" <mcfletch at vrtelecom.com> writes:

> Well...
> 
> def without( source, element):
> 	temp = source[:]
> 	while temp:
> 		try:
> 			temp.remove( element )
> 		except:
> 			break
> 	return temp

Whoa!

Why on *earth* would you use a while/try/break-combination? IMO a much
more natural solution would be:

def without(source, element):
    result = source[:]
    if element in result:
        result.remove(element)
    return result

My point was that I wanted a method in the standard libraries, or,
preferrably as a list method. I guess the closest I got wat the filter
suggestion.

--

  Magnus          Echelon jamming noise:
  Lie             FBI CIA NSA Handgun Assault Bomb Drug Terrorism
  Hetland         Special Forces Delta Force AK47 Hillary Clinton 




More information about the Python-list mailing list