Python generator function
def gen_nums():
n = 0
while n < 4:
yield n
n += 1
Python generator function
def gen_nums():
n = 0
while n < 4:
yield n
n += 1
convert generator to list python
g_to_list = list(g) # where g is a generator
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)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us