Is there a function that applies list of functions to a value?

fp2161 at gmail.com fp2161 at gmail.com
Fri Aug 30 02:06:49 EDT 2013


On Friday, August 30, 2013 4:09:45 AM UTC+2, Steven D'Aprano wrote:
> On Thu, 29 Aug 2013 13:50:39 -0700, fp2161 wrote:
> 
> 
> 
> > My way is so obvious that it may not be that interesting...
> 
> > 
> 
> > def func4(f1,f2,f3,f4):
> 
> >     def anon(x):
> 
> >         f1(f2(f3(f4(x))))
> 
> >     return anon

> I don't think "obvious" is quite the right description. Well, perhaps 
> 
> "obviously wrong" :-)
 
> You also need to define func1 (trivial), func2, func3, func5, func6, 
> 
> func7, func8, ..., func2147483647, plus another master function to choose 
> 
> between them, depending on the number of functions provided as argument.
> I assume that the maximum number of arguments given is 2**31-1. Python 
> 
> may not actually have that limitation, in which case you would need to 
> 
> define additional functions.
> Or... you would have to come up with an implementation which doesn't hard-
> 
> code the number of functions used.
> 
> Steven

I got the generalisation criticism before yours, and generalised it accordingly. Unfortunately it was wrong essentially because it was so obvious that Josh Englsih posted essentially the same one before me...



More information about the Python-list mailing list