TypeError: unhashable type: 'dict' when attempting to hash list - advice sought

kbtyo ahlusar.ahluwalia at gmail.com
Sun Aug 30 13:34:18 EDT 2015


On Sunday, August 30, 2015 at 1:25:13 PM UTC-4, Laura Creighton wrote:
> 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

@Laura - thank you. I observed this earlier. Please see my reply to Ben and MRAB for the most up to date status. 



More information about the Python-list mailing list