[EMAIL PROTECTED] wrote: > Hello, > > I need your help understanding lambda (and doing it a better way > without). > > f = lambda x : x*x [ ... ] > # the idea is now to give the definition of the multiplication of > functions and integers > # (f * c)(xx) := f(x)*c > [lambda xx: f(xx)*y for y in range(1,5)][0](1) > # returns 4 > # I would expect 1*x*x = 1
I think you have to get the value of y at definition time, not at call time: >>> z=[lambda xx, yy=y: (f(xx)*yy) for y in xrange(1,5)] >>> z[0](1) 1 Mel. -- http://mail.python.org/mailman/listinfo/python-list