[Tutor] hash table

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Fri, 21 Dec 2001 12:07:56 -0800 (PST)


On Fri, 21 Dec 2001, Glen Wheeler wrote:

> 
> > If all I really want is an efficient hash table, should I just use a
> > dictionary?  Or is there a better way?
> >
> 
>   Dictionaries are very efficient - I use them all the time.  I guess you
> could use a C hash but really...the performance difference is negligible to
> zero :)

My impression was that a Python dictionary is the same thing as a
"hashtable".  All things that can be used as keys in a dictionary need to
support the hash() function:

###
>>> hash(42)
42
>>> hash("lothlorien")
-435310080
>>> hash(['no', 'good'])
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: unhashable type
###