I’m trying to create a function:
filter(delete,lst)
When someone inputs:
filter(1,[1,2,1])
returns [2]
What I have come up with was to use the list.remove function but it only deletes the first instance of delete.
def filter(delete, lst):
"""
Removes the value or string of delete from the list lst
"""
list(lst)
lst.remove(delete)
print lst
My result:
filter(1,[1,2,1])
returns [2,1]
Try with list comprehensions:
Or alternatively, with the built-in filter function:
And it’s better not to use the name
filterfor your function, since that’s the same name as the built-in function used above