Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to catch stop itteration in generator as None

# creating the list
L = [1,2,3,4,5,6]
# defining the generator
def generator(l):
    for i in l: yield i
    while True: yield  None
        

g = generator(L)

print(next(g)) # 1
print(next(g)) # 2
print(next(g)) # 3
print(next(g)) # 4
print(next(g)) # 5
print(next(g)) # 6
print(next(g)) # None
print(next(g)) # None
print(next(g)) # None
Comment

PREVIOUS NEXT
Code Example
Python :: unhapppy man with monwy 
Python :: python compiler and shell online 
Python :: how to run matrix in python 
Python :: dynamically created queryset for PrimaryKeyRelatedField in drf 
Python :: transverse tensor in pytorch 
Python :: Python - Cómo Jugar archivo Mp3 
Python :: oop - Apa metaclasses di Python 
Python :: grep alternative in python 
Python :: longueur liste python 
Python :: concatenate the squares of numbers in python 
Python :: How to get a mock image in django? 
Python :: countvectorizer minimum frequency 
Python :: Loop per n (batch) 
Python :: get current worker id multiprocessing 
Python :: one2many add tuple 
Python :: tar: Exiting with failure status due to previous errors 
Python :: python which packages depend on package 
Python :: importing modules in kv lang 
Python :: django array of dates 
Python :: django import excel file from same directory 
Python :: fouier transformation in python open cv 
Python :: python print string 
Python :: how to check the version of ployly 
Python :: python discover methods of object/module 
Python :: python tupel from string 
Python :: spacegoat meaning 
Python :: python open file partially 
Python :: python default summary statistics for all columns 
Python :: sorted key len python 
Python :: insert in a sorted list python 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =