L=["apple","banana","mango","kiwi"]
如果用户输入水果,让我们说香蕉,输出必须是
["banana","mango","kiwi","apple"]
我应该使用后移原理吗? 请帮忙。
答案 0 :(得分:0)
你可以试试这个:
from collections import deque
d = deque(["apple","banana","mango","kiwi"])
d.rotate(-list(d).index("banana"))
print(list(d))
输出:
['banana', 'mango', 'kiwi', 'apple']