我有这样的列表和字典:
list_1 = ['if looks kill then i'm murdering]
dic_1 = {"kill": -2, "murdering": -3}
我想提取与字典键匹配的列表项并将其附加到集合中。我有两个问题: 1. 我无法提取与字典中的键匹配的列表项 2. 如何将列表项附加到集合中?
set_1 = set()
for items in list_1:
list_1 = items.lower().split()
for term in dic_1:
forth_list = [words for words in list_1 if term != words]
print forth_list
这将打印
['if', 'looks', 'then', 'i', 'm', 'murdering']
['if', 'looks', 'kill', 'then', 'i', 'm']
set_1.add(forth_list) # this produce a TypeError: unhashable type: 'list'
print set_1