In <[EMAIL PROTECTED]>, Josiah Manson
wrote:

> def make_polys(n):
>       """Make a list of polynomial functions up to order n.
>       """
>       p = lambda x: 1
>       polys = [p]
> 
>       for i in range(n):
>               polys.append(lambda x: polys[i](x)*x)

The `i` is the problem.  It's not evaluated when the lambda *definition*
is executed but when the lambda function is called.  And then `i` is
always == `n`.  You have to explicitly bind it as default value in the
lambda definition:

                polys.append(lambda x, i=i: polys[i](x)*x)

Then it works.

Ciao,
        Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to