Fibonacci, Generators and Python

Python is so beautiful and elegant

See this:

def fib():
    a, b = 0, 1
    while 1:
        yield b
        a, b = b, a+b

if __name__ == '__main__':
    f = fib()
    for i in xrange(1000):
        print f.next()

from: http://www.python.org/dev/peps/pep-0255/

There are no comments on this post

Leave a Reply