Function application optimization.

Bruno Desthuilliers bdesth.nospam at removeme.free.fr
Fri Dec 12 12:59:32 CET 2003


Jacek Generowicz wrote:
> Given
> 
>   fncs = [func1, func2, ..., funcN]
>   args = [arg1,  arg2,  ..., argN]
> 
> How should one spell
> 
>   results = map(lambda f,a: f(a), fncs, args)
> 
> in order to get the result most quickly ?
> 

I dont know if it will be faster (timeit might tell you this), but what 
about something as simple stupid as:

   results = []
   nbfuns = len(fncs)
   for i in range(len):
       results.append(fncs[i](args[i]))

Note that you must have at least len(fncs) args.


HTH,
Bruno





More information about the Python-list mailing list