python generator type code example
Example 1: generator expressions python
>>> even_squares = (x * x for x in range(10)
if x % 2 == 0)
Example 2: python generator
def grepper_gen():
yield "add"
yield "grepper"
yield "answer"
grepper = grepper_gen()
next(grepper)
> add
next(grepper)
> grepper
next(grepper)
> answer
Example 3: typing generator python
def infinite_stream(start: int) -> Iterator[int]:
while True:
yield start
start += 1
def infinite_stream(start: int) -> Generator[int, None, None]:
while True:
yield start
start += 1