【发布时间】:2021-03-10 17:29:50
【问题描述】:
length_word = {'pen':3, 'bird':4, 'computer':8, 'mail':4}
count_word = {'pen':10, 'bird':50, 'computer':3, 'but':45, 'blackboard': 12, 'mail':12}
intersection = length_word.items() - count_word.items()
common_words = {intersection}
错误:TypeError: unhashable type: 'set'
我希望得到这本词典:
outcome = {'pen':10, 'bird':50, 'computer':3, 'mail':12}
谢谢。
【问题讨论】:
-
作为不可散列类型的集合不能是其他集合的一部分,也不能是字典中的键。
-
看到这篇文章,它回答了你的问题:stackoverflow.com/questions/18554012/…
标签: python loops dictionary intersection