list.without()?

Mike Fletcher mcfletch at vrtelecom.com
Mon Nov 15 22:13:40 EST 1999


Well...

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

Seems to work.  I'm not sure if by "standard language" you were saying "in
the standard libraries", but there's certainly no non-standard Python in the
above.

Cheers,
Mike

-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Magnus L. Hetland
Sent: November 15, 1999 7:04 PM
To: python-list at python.org
Subject: list.without()?



Hi!

Is there a function or method in the standard language that can
non-destructively return a list without a specified element? Would it
be possible to add it as a method to lists?

i.e:

# pseudocode

class list:
    def without(self,element):
        temp = self[:]
        temp.remove(element)
        return temp

It might be useful - and sure beats using a temp-variable ;)

--

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

--
http://www.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list