Pre-PEP: __hashable__

Mel Wilson mwilson at the-wire.com
Wed Dec 11 11:32:58 EST 2002


In article <mailman.1039579634.8222.python-list at python.org>,
Lulu of the Lotus-Eaters <mertz at gnosis.cx> 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())

k, d = [0,1], {}
d[tuple(k)] = k
d1 = {}
d1[tuple(d.items())] = 1

        raises TypeError: unhashable type.

   I think the proposed `hashable` really means deep copy.
It's the only way to be sure that the key value doesn't
wiggle around and come unmatched from the hash values in the
(I presume) dictionary tree.

        Regards.        Mel.



More information about the Python-list mailing list