"Updating" lambda functions

Elaine Jackson elainejackson7355 at home.com
Thu Sep 16 13:48:52 EDT 2004


"Oliver Fromme" <olli at haluter.fromme.com> wrote in message
news:2qtl0oF139gn6U1 at uni-berlin.de...

| That works, but it strikes me as unclean and ugly.
| Is there a better way to do it?

I don't like it either. Consider this:

>>> composition = lambda f,g: lambda x: f(g(x))
>>> add_17 = lambda x: x+17
>>> mul_3 = lambda x: 3*x
>>> fu = lambda x:x
>>> fu(3)
3
>>> fu = composition(add_17,fu)
>>> fu(3)
20
>>> fu = composition(mul_3,fu)
>>> fu(3)
60





More information about the Python-list mailing list