[Tutor] Dictionary keys
Gonçalo Rodrigues
op73418@mail.telepac.pt
Mon Nov 4 06:46:01 2002
----- Original Message -----
From: "Simon Wittber (Maptek)" <Simon.Wittber@perth.maptek.com.au>
>I have just one question, is it very 'pythony' to use objects (class
>instances) as dictionary keys?
Yup very Pythonesque. People do that every time.
There are two things that you have to make sure, though. The class has to
define a __hash__ method - computing what is called the hsh value - and it
must be so defined in such a way that if two instances are equal then their
hash values must be the same.
Hope it helps,
G. Rodrigues