TypeError: unhashable type: 'dict' when attempting to hash list - advice sought
Laura Creighton
lac at openend.se
Sun Aug 30 13:24:49 EDT 2015
When you get TypeError: unhashable type: 'dict'
it almost always means that you are trying to use a dict as
a key for a different dict.
Python 2.7.10 (default, Jul 1 2015, 10:54:53)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> d={1:'one', 2:'two', 3:'three'}
>>> d1={1:'A', 2:'B', 3:'C'}
This doesn't work.
>>> print d1[d]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'dict'
This does.
>>> for index in d:
... print d1[index]
...
A
B
C
HTH,
Laura
More information about the Python-list
mailing list