Answers for "convert list to generator python"

1

convert list to generator python

data = [1,23,46,9,2]
#creates a generator object
data_gen = (y for y in data)

# creates a list iterator object
data_iter = iter(data)

# both can be used with next()

next(data_gen) 
# or
next(data_iter)
Posted by: Guest on November-11-2021
1

convert generator to list python

g_to_list = list(g) # where g is a generator
Posted by: Guest on September-07-2020

Code answers related to "convert list to generator python"

Python Answers by Framework

Browse Popular Code Answers by Language