You’re describing the basic use of itertools.count
:
import itertools
squares = (x*x for x in itertools.count())
More Related Contents:
- What happens when start value < end value with range() cmd in Python?
- Understanding generators in Python
- Lazy Method for Reading Big File in Python?
- How to use a decimal range() step value?
- Difference between Python’s Generators and Iterators
- How do I know if a generator is empty from the start?
- Resetting generator object in Python
- Is it possible to implement a Python for range loop without an iterator variable?
- Can iterators be reset in Python?
- Converting “yield from” statement to Python 2.7 code
- How to len(generator()) [duplicate]
- Python generator that groups another iterable into groups of N
- `xrange(2**100)` -> OverflowError: long int too large to convert to int
- Length of generator output [duplicate]
- How to loop backwards in python? [duplicate]
- How to get the n next values of a generator in a list (python)
- Python range() and zip() object type
- Turn functions with a callback into Python generators?
- Best way to receive the ‘return’ value from a python generator
- How does the Python’s range function work?
- Handle an exception thrown in a generator
- How to slice a generator object or iterator?
- What does the “yield” keyword do in Python?
- Print a list in reverse order with range()?
- Range as dictionary key in Python
- Python IndexError: list index out of range
- Why do list comprehensions write to the loop variable, but generators don’t? [duplicate]
- Python: Mapping from intervals to values
- Python using exceptions for control flow considered bad?
- How can the built-in range function take a single argument or three?