[Tutor] how to understand unhashable type: 'list'
wprins at gmail.com
Thu Nov 17 15:16:03 CET 2011
On 17 November 2011 14:04, lina <lina.lastname at gmail.com> wrote:
> >> Traceback (most recent call last):
> >> File "<pyshell#292>", line 1, in <module>
> >> weight[list1]=1
> >> TypeError: unhashable type: 'list'
> > You are trying to store a list as a key inside a dict. This cannot be
> > because lists (like all mutable types) can't be hashed.
> I checked online dictionary, still confused about hashed. is it equal
> to mix together or mess together?
No.... you need to think programming/computer science where hash/hashing
has a different meaning. See wikipedia:
Also see the description for "hashable" in the Python glossary:
Basically hashing is a way to convert something (often a string) into an
identifying number (not neccesarily but usually unique) in order to use
this number as a token for the original thing. Aside, you can infer that
that because the "dict" code complains about hashing implies that dicts
themselves are essentially implemented as hash tables... ;)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor