python generator to list code example
Example 1: convert generator to list python
g_to_list = list(g)
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: python generator
def count_to_ten_generator():
for number in range(10):
yield number
my_generator = count_to_ten_generator()
first_number = next(my_generator)
list_or_the_rest = list(my_generator)
Example 4: generator expressions python
>>> for x in even_squares:
... print(x)
0
4
16
36
64