Efficient way to rotate a list in python

后端 未结 26 1204
一生所求
一生所求 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:43

    for similar functionality as shift in other languages:

    def shift(l):
        x = l[0]
        del(l[0])
        return x
    

提交回复
热议问题