我有一个我希望与其他列表匹配的诅咒词列表以删除匹配.我通常会单独使用list.remove('entry'),但是循环遍历另一个列表中的条目列表 - 然后删除它们让我感到难过.有任何想法吗?
Fac*_*sco 10
使用filter:
>>> words = ['there', 'was', 'a', 'ffff', 'time', 'ssss']
>>> curses = set(['ffff', 'ssss'])
>>> filter(lambda x: x not in curses, words)
['there', 'was', 'a', 'time']
>>>
Run Code Online (Sandbox Code Playgroud)
它也可以通过列表理解来完成:
>>> [x for x in words if x not in curses]
Run Code Online (Sandbox Code Playgroud)