I have a requirement to rotate a varying length list so that a specified value is centred in the list (i.e. rotating left or right as required).
Say I have a list:
lst = [1, 2, 3, 4, 5]
So assuming 1 is specified, then the rotated list should look like this:
lst = [4, 5, 1, 2, 3]
I know the slicing formula for rotating a list is lst = lst[n:] + lst[:n] but I'm having challenges dynamically coming up with n. I've tried using len(lst) // 2) and trying to use the list index of the specified value against that to work out n, but I can't seem to get it right.
Any suggestions? (this task is from a JetBrains Academy course that doesn't explain things well...)