gpt4 book ai didi

python - 不可散列类型 : 'dict' Type Error

转载 作者:行者123 更新时间:2023-11-28 22:46:28 25 4
gpt4 key购买 nike

<分区>

假设我有这本字典:

items = {1: {'title': u'testing123', 'description': u'testing456'},
2: {'description': u'testing123', 'description': u'testing456'},
3: {'description': u'testing123', 'description': u'testing456'},
4: {'description': u'testing123', 'description': u'testing456'},
5: {'description': u'testing123', 'description': u'testing456'},
6: {'description': u'somethingelse', 'description': u'somethingelse'}}

我想过滤掉重复的值,这样最后我会得到

{1: {'title': u'testing123', 'description': u'testing456'}, 6: {'title': u'something', 'description': u'somethingelse'}}

我写了这段代码:

dic = {}

for key, value in items.items():
if not set(value.values()).issubset(set(dic.values())):
dic[key] = value

但是我收到错误消息 TypeError: unhashable type: 'dict'。我不确定为什么会发生这种情况以及如何解决它。

这受到 another question 的启发,我试图解决它但失败了。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com