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

Bengt Richter bokr at oz.net
Mon Nov 11 15:39:23 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?

>>> import sys; ['' for a in [[1,1]] for i in xrange(20) if a.append(a.pop(0)+a[0]) or sys.stdout.write('%s '%a[0])]
1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 []


Regards,
Bengt Richter



More information about the Python-list mailing list