L=["apple","banana","mango","kiwi"]
If the user enters a fruit, let's say banana, the output must be
["banana","mango","kiwi","apple"]
Should I use the back shifting principle? Please help.
L=["apple","banana","mango","kiwi"]
If the user enters a fruit, let's say banana, the output must be
["banana","mango","kiwi","apple"]
Should I use the back shifting principle? Please help.
You can try this:
from collections import deque
d = deque(["apple","banana","mango","kiwi"])
d.rotate(-list(d).index("banana"))
print(list(d))
Output:
['banana', 'mango', 'kiwi', 'apple']