Is this a good use for lambda

Harlin Seritt hps3 at seritt.org
Fri Dec 17 19:16:44 EST 2004


Charlie Taylor wrote:

> 
> I find that I use lambda functions mainly for callbacks to things like
> integration or root finding routines as follows.
> 
> flow = integrate(lambda x: 2.0*pi * d(x)* v(x) * sin(a(x)),xBeg, xEnd)
> 
> root = findRoot(xBeg, xEnd,
>        lambda x: y2+ lp*(x-x2) -wallFunc( x )[0], tolerance=1.0E-15)
> 
> I have tried using named functions instead of using lambda functions,
> however, I always end up with a convoluted, hard to follow mess.
> 
> Is there a better solution than a lambda in the above situations?

Yes. Write a separate function for it. It may actually take less time and be
a good deal more readable. Also, you'll be able to call this mess again if
you need to. :-)

-- 
Harlin Seritt



More information about the Python-list mailing list