Is this a good use for lambda

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Tue Dec 21 04:04:52 EST 2004


Replying to myself, with a simpler version:

Roel Schroeven wrote:
> Alan G Isaac wrote:
>> def compose(list_of_functions): return reduce(lambda f, g: lambda x:
>> f(g(x)), list_of_functions)
> 
> def compose(list_of_functions):
>     def compose2(f, g):
>         def func(x):
>             return f(g(x))
>         return func
>     return reduce(compose2, list_of_functions)

def compose(lof):
     def func(x):
         for f in reversed(lof):
             x = f(x)
         return x
     return func

Still not sure what version is best though.

-- 
"Codito ergo sum"
Roel Schroeven



More information about the Python-list mailing list