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

Mel Wilson mwilson at the-wire.com
Mon Nov 11 14:26:25 EST 2002


In article </f9z9ks/KbEa089yn at the-wire.com>,
mwilson at the-wire.com (Mel Wilson) wrote:
>In article <fa61a3d8.0211110720.16a645f8 at posting.google.com>,
>a_human_work at hotmail.com (Pittaya) wrote:
>> [ ... ]                                     find fibanicci series in
>>a single line of [Perl] code.
>>perl -le '$b=1; print $a+=$b while print $b+=$a'

>   One-liner contests are noxious, but what the heck; the
>first 10, governed by the xrange ..

Well, one-liners clearly are not your forte.

>print reduce (lambda x,y: (x[1],x[0]+x[1], x[2]+[x[1]]), xrange(10), (0,1,[]))[2]

Pretty lame compared to

print reduce (lambda x,y: x + [x[-1]+x[-2]], xrange(10), [1, 1] )

right?

        Regards.        Mel.



More information about the Python-list mailing list