Can python find fibonacci series in a single line of code?
Fernando Pérez
fperez528 at yahoo.com
Mon Nov 11 17:48:51 EST 2002
More information about the Python-list mailing list
Mon Nov 11 17:48:51 EST 2002
- Previous message (by thread): Can python find fibonacci series in a single line of code?
- Next message (by thread): Can python find fibonacci series in a single line of code?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
logistix wrote: > a_human_work at hotmail.com (Pittaya) wrote in message > news:<fa61a3d8.0211110720.16a645f8 at posting.google.com>... >> 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? > > Guys, c'mon. How are you supposed to lock up your computer when you > only print the first 10 numbers? > > python -c "a,b=1,1;exec('while 1:\n\tglobal a,b\n\tprint > a\n\ta,b=b,a+b\n\n')" The globals aren't needed, exec() defaults to your current namespace: python -c "a,b=1,1;exec('while 1:\n\tprint a\n\ta,b=b,a+b\n')" Just how annoying this is to even read should make the point of the sillyness of one-liner battles :) Cheers, f
- Previous message (by thread): Can python find fibonacci series in a single line of code?
- Next message (by thread): Can python find fibonacci series in a single line of code?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list