Newbie question about dictionaries

Vladimir Cherepanov vovka_foreverREMOVE_THIS at hotmail.com
Mon Jul 29 10:46:17 EDT 2002


Thanks for the quick answer!
Is it right then that I have to implement a custom class for key objects if
I want to use a custom hash function?


"Gerhard Haering" <gerhard.haering at gmx.de> wrote in message
news:slrnakajpi.t8.gerhard.haering at lilith.my-fqdn.de...
> In article <ai3hvh$2a8n$1 at gavrilo.mtu.ru>, Vladimir Cherepanov wrote:
> > I've read that dictionaries are implemented as hash tables. Is there any
way
> > to specify a hash function?
>
> Sure there is. You need to implement a __hash__ method. It's described
here:
> http://www.python.org/doc/current/ref/customization.html
>
> Gerhard
> --
> mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
> web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
> public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
> reduce(lambda x,y:x+y,map(lambda
x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))




More information about the Python-list mailing list