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

Michael Stenner mstenner at phy.duke.edu
Mon Nov 11 12:40:55 EST 2002


On Mon, Nov 11, 2002 at 07:20:20AM -0800, 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?

Not well, no.  If you or your friend find yourselves needing to do
this kind of thing often, then perl is probably a better choice for
those tasks.  I use both perl and python.  I like them both.  For this
sort of thing perl is better suited, and I think few would argue with
that.

The point others are trying to make (somewhat defensively, perhaps) is
that the same syntax choices that make this easier in perl often leads
to clearer python programs with the same amount of programmer effort.
Personally, I find that more appealing when writing programs of any
significant size.

Nonetheless, I DO use perl when I want to quickly whip off stuff like
this from the command line.  If this is a battle in some silly
language war, then give your friend the victory.  It's a small one.

					-Michael
-- 
  Michael Stenner                       Office Phone: 919-660-2513
  Duke University, Dept. of Physics       mstenner at phy.duke.edu
  Box 90305, Durham N.C. 27708-0305




More information about the Python-list mailing list