I need to cycle through a list for starting position between 1-4
using itertools
I am able to cycle through the list
positions = it
Use slices of the original list:
In [15]: def custom_slice(lst, start):
....: return cycle(lst[start:] + lst[:start + 1])
Demo:
In [16]: positions = custom_slice(lst, 2)
In [17]: next(positions)
Out[17]: 3
In [18]: next(positions)
Out[18]: 4
In [19]: next(positions)
Out[19]: 1
In [20]: next(positions)
Out[20]: 2