pure generators

bearophile bearophileHUGS at lycos.com
Thu May 13 13:10:53 PDT 2010


Graham Fawcett:

> def fibonacci():
>     a, b = 1, 1
>     while True:
>         yield a
>         a, b = b, a + b

This is my version I use (doctests and docstring removed), a bit faster with Python 2.x:

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

Thank you for your explanations. I am too much ignorant still to talk about those things :-)

Bye,
bearophile


More information about the Digitalmars-d mailing list