Reputation: 23
I am attempting to split a string and then take a keyword from that string and find it in a dictionary. I would then want to call out that part of the dictionary, but i run into this error -
TypeError: unhashable type:set
- on the last line:
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])
Upvotes: 1
Views: 1002
Reputation: 1986
I'm not sure that any of the other answerers are trying to understand what you're doing.
Try this. I'm not sure what you plan on for problems
, but this will at least run and hopefully get you in the right direction:
solutions = {'display': 'take it to a specialist to get fixed','screen':'test'}
problems = ['display','screen','cracked','broken','clear']
query = raw_input("What is the problem? ")
for word in query.split():
print(word)
print(solutions.get(word))
Notice the change of input
to raw_input
and accessing the keys of the dictionary as str
types rather than a set
.
Upvotes: 0
Reputation: 1933
When you do keyword = set(words) & set(problems)
, keyword becomes a set
. You probably want to set keyword to an element from that set
using the pop
function.
i.e.
keyword = keyword.pop()
Upvotes: 2