Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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
 
PREVIOUS NEXT
Tagged: #catch #stop #itteration #generator #None
ADD COMMENT
Topic
Name
4+8 =