lambda (and reduce) are valuable

David Isaac aisaac0 at verizon.net
Mon Dec 12 00:45:57 EST 2005


> Alan Isaac wrote:
> >>> #evaluate polynomial (coefs) at x using Horner's rule
> >>> def horner(coefs,x): return reduce(lambda a1,a2: a1*x+a2,coefs)
> > It just cannot get simpler or more expressive.


"Peter Otten" <__peter__ at web.de> wrote in message
news:dne702$j1q$02$1 at news.t-online.com...
> But is it correct?

Yes.

> Are we merely employing different conventions for the order of
coefficients
> or is that simple and expressive lambda/reduce stuff obscuring an error?

It is too simple and expressive to obscure an error.   ;-)
This is particularly important since coefficient order is not standardized
across uses.

Cheers,
Alan Isaac





More information about the Python-list mailing list