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.

Alan Kavanagh
  • 9,425
  • 7
  • 41
  • 65

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
  • 69,937
  • 8
  • 61
  • 102