python列表【左移】【右移】

  1. 左移
#A为原始列表,a为左移位数
def list_move_left(A,a):
    for i in range(a):
        A.insert(len(A),A[0])
        A.remove(A[0])
    return A
  1. 右移
#A为原始列表,a为右移位数
def list_move_right(A,a):
    for i in range(a):
        A.insert(0,A.pop())
    return A
原文地址:https://www.cnblogs.com/amize/p/15744735.html