Home » TypeError: unhashable type: ‘dict’

TypeError: unhashable type: ‘dict’

To solve TypeError: unhashable type: ‘dict’ error follow below methods.

The Python programming language has strict rules regarding what can be used as a key in a dictionary. All keys in a Python dictionary must be hashable.

If you try to add a key to a dictionary with an unhashable key type, you’ll get the “TypeError: unhashable type: ‘dict'” problem.


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'

How to solve TypeError: unhashable type: ‘dict’ ?

When you try to create an item in a dictionary whose key is an unhashable object, you get the “TypeError: unhashable type: ‘dict'” error. In a dictionary, only immutable objects such as strings, tuples, and integers can be used as keys.

To avoid this problem, only utilise hashable objects when creating an item in a dictionary.

import json

a={"a":10, "b":20}
b={"b":20, "a":10}
c = [json.dumps(a), json.dumps(b)]

json.dumps(a) in c

Hope the above solution works.

Also read :

requests.exceptions.SSLError: [Errno 1] _ssl.c:503: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
TypeError: unhashable type: ‘list’