order independent hash?
Peter Otten
__peter__ at web.de
Wed Nov 30 07:47:13 EST 2011
Neal Becker wrote:
> I like to hash a list of words (actually, the command line args of my
> program) in such a way that different words will create different hash,
> but not sensitive to the order of the words. Any ideas?
You mean a typical python hash value which would be /likely/ to differ for
different lists and /guaranteed/ to be equal for equal lists is not good
enough? Because that would be easy:
args = sys.argv[1:]
hash(tuple(sorted(args))) # consider duplicate args
hash(frozenset(args)) # ignore duplicate args
More information about the Python-list
mailing list