Fibonacci, Generators and Python

2007 December 16
by Tzury Bar Yochay

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/

2 Responses leave one →
  1. 2008 October 18
    pythonisms permalink

    I agree… love the terse yet readable code. thx for posting.

  2. 2009 May 20

    Good internet site / will definitely visit again:D

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS