从左向尾移动时可以指定起始位置和要移动的元素个数
从右向首移动时,若要指定位置是从右向左数,示例未使用。
def rmove(lst,ista,num):
for x in range(num):
lst.append(lst.pop(ista-1))
return lst
#调用:
arr= [1, 2, 3, 4, 5, 6, 7]
rmove(arr,1,3)
#结果:
[4, 5, 6, 7, 1, 2, 3]
def lmove(lst,num):
for x in range(num):
lst.insert(0,lst.pop(-1))
return lst
#调用:
arr = [1, 2, 3, 4, 5, 6, 7]
lmove(arr,3)
#结果:
[5, 6, 7, 1, 2, 3, 4]
博客介绍了元素移动相关内容,从左向尾移动时可指定起始位置和要移动的元素个数,从右向首移动时指定位置是从右向左数,但示例未使用。

被折叠的 条评论
为什么被折叠?



