Efficient way to rotate a list in python

后端 未结 26 1792
一生所求
一生所求 2020-11-22 03:14

What is the most efficient way to rotate a list in python? Right now I have something like this:

>>> def rotate(l, n):
...     return l[n:] + l[:n]         


        
26条回答
  •  暖寄归人
    2020-11-22 03:37

    I have similar thing. For example, to shift by two...

    def Shift(*args):
        return args[len(args)-2:]+args[:len(args)-2]
    

提交回复
热议问题