General Hash Functions In Python

Paul Rubin http
Mon Jul 17 02:27:13 EDT 2006


"Arash Partow" <partow at gmail.com> writes:
> I've ported various hash functions to python if anyone is interested:

Are these useful for any particular interoperability purposes?
Otherwise I'd say just one such hash is plenty, or maybe don't even
bother, since Python's built-in dicts are sufficient for most
applications that call for hashing, and the cryptographic hashes are
available for when you really care about uniformity of the hash
output.

>     for i in range(len(key)):
>       hash = hash * a + ord(key[i])
>       a = a * b

As a stylistic issue, I'd write this:

  for c in key:
     hash = hash * a + ord(c)
     a *= b

and similarly for the other similar loops.



More information about the Python-list mailing list