Is this a good use for lambda
Terry Reedy
tjreedy at udel.edu
Sat Dec 18 03:27:18 EST 2004
More information about the Python-list mailing list
Sat Dec 18 03:27:18 EST 2004
- Previous message (by thread): Is this a good use for lambda
- Next message (by thread): Is this a good use for lambda
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Charlie Taylor" <charlie at ezweave.com> wrote in message news:20041217235613.1A1761E4004 at bag.python.org... > > 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) To each there own is my philosophy. However, with multiple arguments, I might prefer def f(x): return 2.0*pi * d(x)* v(x) * sin(a(x)) flow = integrate(f, xBeg, xEnd) def g(x): return y2+ lp*(x-x2) -wallFunc( x )[0] root = findRoot(xBeg, xEnd, g, tolerance=1.0E-15) even if I might use lambda initially. (And the above is in no way a 'mess'.) In any case, as soon as one wants to do even two things with a function -- plot and integrate, or integrate with two methods and compare, or ditto with findRoot, or calculate g(root) after findRoot, one will want a separate def statement. Terry J. Reedy
- Previous message (by thread): Is this a good use for lambda
- Next message (by thread): Is this a good use for lambda
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list