hashing an array - howto

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Fri Sep 5 11:18:52 EDT 2008


Helmut Jarausch:
> I need to hash arrays of integers (from the hash module).

One of the possible solutions is to hash the equivalent tuple, but it
requires some memory (your sequence must not be tuples already):

assert not isinstance(somelist, tuple)
hash(tuple(somelist))

This is an alternative solution, it doesn't use much memory, but I am
not sure it works correctly:

from operator import xor
hash(reduce(xor, somelist))

Bye,
bearophile



More information about the Python-list mailing list