Pre-PEP: __hashable__

Chad Netzer cnetzer at mail.arc.nasa.gov
Tue Dec 10 23:41:41 EST 2002


On Tuesday 10 December 2002 20:02, Lulu of the Lotus-Eaters wrote:
> Chad Netzer <cnetzer at mail.arc.nasa.gov> wrote previously:
> |It would be nice to conceptually be able to have an immutable
> |dictionary type, to use as a key.
>
> What's wrong with:
>
>     key = tuple(dct.items())

>>> a
{'a': {'b': 2}}
>>> a.items()
[('a', {'b': 2})]
>>> tuple(a.items())
(('a', {'b': 2}),)
>>> c ={}
>>> c[ tuple(a.items()) ] = "bacon" 
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: dict objects are unhashable
>>> 

Not all tuples are hashable.  Actually, that clears up one final 
point of discussion I was having with Tim Delaney.  Tuples are NOT 
replacements for his immutablelists, since his immutablelists ARE 
meant to always be hashable (I assume, or else they cannot be 
created...)

So, Tim, if you are reading this, I think that makes the score 
{"you" : 5, "me" : 0}  :)

-- 
Bay Area Python Interest Group - http://www.baypiggies.net/

Chad Netzer
cnetzer at mail.arc.nasa.gov




More information about the Python-list mailing list