one method would be to use itertools.islice
>>> gen = (x for x in range(10))
>>> index = 5
>>> next(itertools.islice(gen, index, None))
5
More Related Contents:
- Understanding generators in Python
- Generator expressions vs. list comprehensions
- Lazy Method for Reading Big File in Python?
- Resetting generator object in Python
- What’s the shortest way to count the number of items in a generator/iterator?
- how to split an iterable in constant-size chunks
- Is there a generator version of `string.split()` in Python?
- Python random sample with a generator / iterable / iterator
- How to look ahead one element (peek) in a Python generator?
- Converting “yield from” statement to Python 2.7 code
- How to len(generator()) [duplicate]
- Python generator that groups another iterable into groups of N
- Is there an expression for an infinite iterator?
- Cartesian product of a dictionary of lists
- When is not a good time to use python generators?
- How to get the n next values of a generator in a list (python)
- How can I generate all possible IPs from a list of ip ranges in Python?
- Turn functions with a callback into Python generators?
- Best way to receive the ‘return’ value from a python generator
- Handle an exception thrown in a generator
- Python: using a recursive algorithm as a generator
- How to slice a generator object or iterator?
- What is the purpose of the “send” function on Python generators?
- Return in generator together with yield
- What does the “yield” keyword do in Python?
- How to clone a Python generator object?
- Why do list comprehensions write to the loop variable, but generators don’t? [duplicate]
- How to use fit_generator with multiple inputs
- How to create the union of many sets using a generator expression?
- Python using exceptions for control flow considered bad?