Yes, you can use itertools.islice() , which can slice the generator as you want -
>>> def a():
... for i in range(10):
... yield i
...
>>>
>>>
>>> x = a()
>>> import itertools
>>> for i in itertools.islice(x, 2, None):
... print(i)
...
2
3
4
5
6
7
8
9
Please note, though you are not manually doing the multiple next() , it is being internally done by islice() . You cannot reach at the required index until you iterate till it (islice just does that for you , instead of you have to write multiple next() , etc).
The signature of itertools.islice is -
itertools.islice(iterable, stop)
itertools.islice(iterable, start, stop[, step])
The first argument is always the iterable, then if you pass in only 2 arguments, second argument is interpreted as the stop index (exclusive, meaning it does not return the stop index element).
If there are 3 or 4 arguments to it , second argument is treated as the start index (index) , third argument as the stop (exclusive) , and if fourth argument is specified its treated as the step value.
yielding from the element you want. Otherwise by definition the preceding values must be calculated (example: generator for the Fibonacci sequence).