list.without()?

Hans Nowak ivnowa at hvision.nl
Tue Nov 16 07:18:33 CET 1999


On 16 Nov 99, Magnus L. Hetland wrote:

> 
> 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

Hmmz... Why a method?

def without(lst, elem):
    return filter(lambda x, elem=elem: x != elem, lst)


--Hans Nowak (zephyrfalcon at hvision.nl)
Homepage: http://fly.to/zephyrfalcon
You call me a masterless man. You are wrong. I am my own master.




More information about the Python-list mailing list