order independent hash?

88888 Dihedral dihedral88888 at googlemail.com
Thu Dec 1 10:35:32 EST 2011


On Wednesday, November 30, 2011 8:47:13 PM UTC+8, Peter Otten wrote:
> 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

I knew a hash can replace a bi-directional linked list.
The value  can be a multi-field string  to be parsed for further actions. 
Is this what you are asking?



More information about the Python-list mailing list