N = 10
target = [2, 9, 5]
lst = list(range(1, N+1))
count = 0
for num in target:
idx = lst.index(num)
if idx <= len(lst)//2:
count += idx
lst = lst[idx:] + lst[:idx]
else:
count += len(lst) - idx
lst = lst[-(len(lst)-idx):] + lst[:-(len(lst)-idx)]
lst.pop(0)
print(count)
To embed this project on your website, copy the following code and paste it into your website's HTML: