I have this piece of code:
for element in json[referenceElement].keys():
When I run that code, I get this error:
TypeError: unhashable type: ‘dict’
What is the cause of that error and what can I do to fix it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
From the error, I infer that
referenceElementis a dictionary (see repro below). A dictionary cannot be hashed and therefore cannot be used as a key to another dictionary (or itself for that matter!).You probably meant either
for element in referenceElement.keys()orfor element in json['referenceElement'].keys(). With more context on what typesjsonandreferenceElementare and what they contain, we will be able to better help you if neither solution works.