Retrieve an item from a dictionary using an arbitrary object as the key
abcd
codecraig at gmail.com
Tue Apr 3 13:33:58 EDT 2007
> You'll need __eq__ for testing if two objects are equivalent, and
> __hash__ for calculating object's hash value.
>
> class Type:
> def __init__(self, val):
> self.val = val
>
> def __eq__(self, other):
> return self.val == other.val
>
> def __hash__(self):
> return hash(self.val)
that's exactly what I needed, thanks.
More information about the Python-list
mailing list