[Python-Dev] d.get_key(key) -> key?

Ka-Ping Yee ping@zesty.ca
Wed, 5 Jun 2002 16:40:16 -0500 (CDT)


On 5 Jun 2002, Daniel 'eikeon' Krech wrote:
>
> Is there or could there be an efficient way to get an existing key from
> a dictionary given a key that is == but whose id is not. For example:

If i understand you correctly, a good way to solve this problem is to
provide a __hash__ method on the objects that you are using as keys to
your dictionary.  Dictionaries look up keys by hash equality.

Note that you will have to ensure that the keys are immutable (i.e.
once they are put in the dictionary, they should never change).


-- ?!ng