Most pythonic way of rotating a circular list to a canonical point
joel.goldstick at gmail.com
Sun Aug 2 00:58:14 CEST 2015
On Sat, Aug 1, 2015 at 6:51 PM, Lukas Barth <mail at tinloaf.de> wrote:
> On Saturday, August 1, 2015 at 11:37:48 PM UTC+2, Emile van Sebille wrote:
>> Well, it looks to me that I don't know what a 'canonical rotation' is --
> That's because it is not defined. ;)
> I need a way to rotate one of these lists in a way so that it will produce the same output every time, regardless of what the input rotation was.
> [0,1,2,3,4] => [0,1,2,3,4]
> [2,3,4,0,1] => [0,1,2,3,4]
> [3,4,0,1,2] => [0,1,2,3,4]
> It doesn't have to be "[0,1,2,3,4]", it can just as well be [2,3,4,1,0], as long as it's always the same.
> Did that make it clearer?
> Thanks a lot,
I've been following along. The early suggestion to double one list
and see if the second list is in the double list seems to prove they
are the same -- one is just rotated to a different starting point. I
don't understand the term 'canonical' in this example, but what is it
that the solution given doesn't provide for you?
More information about the Python-list