Can python find fibonacci series in a single line of code?

Anton Vredegoor anton at vredegoor.doge.nl
Mon Nov 11 14:42:03 EST 2002


On 11 Nov 2002 07:20:20 -0800, a_human_work at hotmail.com (Pittaya)
wrote:

>My Perl-addicted friend shows me that he can find fibanicci series in
>a single line of code.
>
>perl -le '$b=1; print $a+=$b while print $b+=$a'
>
>can python do something like this?

Sure, use a dictionary ...

import sys;d={0:1,1:1};[d.get(sys.stdout.write(str(d[0])+"\n"),\
d.update({0:d[0]+d[1],1:d[0]})) for i in range(10)]

Anton.





More information about the Python-list mailing list