我试图创建一个函数:的Python:创建一个过滤功能
filter(delete,lst)
当有人输入:
filter(1,[1,2,1])
回报[2]
我已经想出了以使用list.remove函数,但它只会删除第一个删除实例。
def filter(delete, lst):
"""
Removes the value or string of delete from the list lst
"""
list(lst)
lst.remove(delete)
print lst
我的结果:
filter(1,[1,2,1])
回报[2,1]
http://stackoverflow.com/questions/1157106/remove-all-occurences-of-a-value-from-a-python-list – Chad
我建议为你的功能选择一个不同的名字。有一个内置的“过滤器”功能,你会掩盖它。 – Avaris
我称为我的功能“过滤器”的原因是在本指导 – HighAllegiant