Since the accepted answer for a similar question Efficient iteration over slice in Python does not offer O(1) running time, I am creating a separate question here.
Let's say we have a list l of size n, and a slice of size k << n that starts in a middle (n/2).
It is very trivial to iterate in a for-in loop optimally:
for i in range(n//2,n//2+k)
#do something with l[i]
...
However my goal is to create an iterator over the slice using standard python tools, so i could use that iterator later on for chaining, filtering, and subslicing using itertools.
Couple standard options are not really good:
iter(l[n//2:n//2+k])
will actually use O(k) extra space for a copy
itertools.islice(l, n//2, n//2+k)
will use O(1) space, but O(n) extra running time to reach the slice range.