Using Generators for Lazy Iteration in Python


Create iterables that generate items one at a time.

Source Code

def count_down(n):
    while n > 0:
        yield n
        n -= 1
for i in count_down(5):
    print(i)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments