gpt4 book ai didi

python - 字典类型错误: unhashable type:set

转载 作者:行者123 更新时间:2023-12-01 04:26:11 26 4
gpt4 key购买 nike

我试图分割一个字符串,然后从该字符串中取出一个关键字并在字典中找到它。然后我想调出字典的那部分,但我遇到了这个错误 -

TypeError: unhashable type:set

-最后一行:

solutions = {'display': 'take it to a specialist to get fixed','screen':'test'}
problems = ['display','screen','cracked','broken','clear']``
words = ()
query = input("What is the problem? ")
query_split = query.split()
words = query_split
keyword = set(words) & set(problems)
print(keyword)
print (solutions[keyword])

最佳答案

当您执行keyword = set(words) & set(problems)时,keyword 就变成了set。您可能想使用 pop 函数将关键字设置为该 set 中的元素。

关键字=keyword.pop()

关于python - 字典类型错误: unhashable type:set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33112227/

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