<分区> 分区>
我在 python 中有一个列表 [a,b,c,d],我通过使用 for 循环遍历索引将它向左移动,我的结果是 [b, c,d,a].
现在我计划将它向右移动,我假设结果将是 [d,a,b,c],但我无法为其编写代码。
谁能给我建议代码和概念?
这是我向左移动的代码。
def shift_left(L):
first_item = L[0]
for i in range (1, len(L)):
L[i-1] = L[i]
L[-1] = first_item
