Entry
list.without() (Removing element from list)
Jul 5th, 2000 10:02
Nathan Wallace, Hans Nowak, Snippet 288, Python Snippet Support Team
"""
Packages: basic_datatypes.lists
"""
"""
> 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)