Is this a good use for lambda

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Tue Dec 21 09:55:21 CET 2004


Alan G Isaac wrote:
> I need a clarification of the argument.
> Are the opponents saying that I should not be able to:
> 
> def compose(list_of_functions): return reduce(lambda f, g: lambda x:
> f(g(x)), list_of_functions)

Personally, I think something like this is a place where lambdas are 
probably better than named functions. Still, you can do this without 
lambdas:

def compose(list_of_functions):
     def compose2(f, g):
         def func(x):
             return f(g(x))
         return func
     return reduce(compose2, list_of_functions)
			
> And may I see the proposed "better" replacement for function composition.

Whether this is better or not, I don't know.

-- 
"Codito ergo sum"
Roel Schroeven



More information about the Python-list mailing list