hash() algorithm

Tim Peters tim.peters at gmail.com
Wed Jul 21 22:46:03 CEST 2004

[Benoît Dejean]
> hi. Is the hash() algorithm standard ? Does hash(some_string) will always
> return the same hash code on every arch ?

No, and in fact it's almost certain to deliver a different hash on a
32-bit machine than on a 64-bit machine (Python hash codes are the
same size as the native platform C "long" type).  Python doesn't
promise to deliver the same hash codes across releases either
(although it usually does anyway).

> i need to use a ~checksum function, like md5, but i was also thinking
> about hash() which is obviously simpler. So i can safely rely on hash()
> behaviour so i can use it to generate ~strong and portable
> identifier/checksum ?

It's not strong.  It's easy to find distinct strings with the same
Python hash; it's widely thought to be intractable to do the same wrt
MD5 or SHA hashes.

More information about the Python-list mailing list