Most pythonic way of rotating a circular list to a canonical point
Cameron Simpson
cs at zip.com.au
Sat Aug 1 18:25:30 EDT 2015
On 01Aug2015 14:24, Lukas Barth <mail at tinloaf.de> wrote:
>Perhaps I should clarify a bit:
>- I definitely need a "canonical rotation" - just a comparison result is not enough
Fine. This also eliminates any solution which just computes a hash.
>- It does not matter what that rotation is. Starting with the smallest element was just an idea by me, any rotation that can easily produced will do.
That's a fine way to start, but more work than is needed.
Might I suggest instead simply starting with the leftmost element in the first
list; call this elem0. Then walk the second list from 0 to len(list2). If that
element equals elem0, _then_ compare the list at that point as you suggested.
Is there an aspect of this which doesn't work?
Cheers,
Cameron Simpson <cs at zip.com.au>
More information about the Python-list
mailing list