Generator countdown

Question

Generator demonstrating countdown from a particular value.

Solution

def countdown(n):
    while n > 0:
        yield n
        n -= 1

for i in countdown(5):
    print i
Run this
Comments by Disqus