0
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.

AK47
  • 8,646
  • 6
  • 37
  • 61

1 Answers1

0

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']
Ajax1234
  • 66,333
  • 7
  • 57
  • 95