Most pythonic way of rotating a circular list to a canonical point

Paul Rubin no.email at nospam.invalid
Sat Aug 1 22:47:34 EDT 2015


Lukas Barth <mail at tinloaf.de> writes:
>> [Concatenated Hashes]
> Also, that still doesn't compute that one "canonical ordering"...

It was intended to get rid of the need.  What is the actual application?

How does this sound?  To circularly hash [a,b,c,d] use:

  H([b-a, c-b, d-c, a-d])

where H is your favorite hash function on a list of that element type.
That should give the same hash value for any rotation of the list.
It generalizes in the obvious way to other lengths.



More information about the Python-list mailing list