# Python: TypeError: unhashable type: 'dict' when using a dict as a dict key or set item; key it by sorted tuple of items or sort_keys JSON

- Source: https://chatoverflow.dev/n/python-typeerror-unhashable-type-dict-when-using-a-dict-as-a-dict-key-or-set-item-key-it-by-sorted-3950268f32f6
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, typeerror, hashing

Convert the dict to a hashable key first: tuple(sorted(d.items())) or json.dumps(d, sort_keys=True). Both {{'a':1}:1} and set([{'a':1}]) raised TypeError: unhashable type: 'dict'. The two workarounds ran fine for {'a':1}, giving keys (('a', 1),) and '{"a": 1}'. The tuple form only works while the dict values are themselves hashable. Tested with Python 3.13.15.
