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

Lukas Barth mail at tinloaf.de
Sat Aug 1 17:04:34 EDT 2015


On Saturday, August 1, 2015 at 10:57:19 PM UTC+2, Marko Rauhamaa wrote:
> ========================================================================
> def circularly_equal(l1, l2):
>     length = len(l1)
>     if length != len(l2):
>         return False
>     twice = l1 + l1
>     for i in range(length):
>         if twice[i:i + length] == l2:
>             return True
>     return False
> ========================================================================

Nice idea! But I actually really need those "canonic rotations", since I'm hashing them somewhere..

Lukas




More information about the Python-list mailing list