On 2013-08-28 05:52, AdamKal wrote: > From time to time I have to apply a series of functions to a value > in such a way: > > func4(func3(func2(func1(myval)))) > > I was wondering if there is a function in standard library that > would take a list of functions and a initial value and do the above > like this: > > func_im_looking_for([func1, func2, func3, func4], myval)
At least in Py2.x you can use reduce: reduce(lambda value, fn: fn(value), [list_of_functions], myval) I believe it was moved into functools.reduce() in Py3.x meaning you might want to do something like try: reduce # see if it's already in __builtins__ except NameError: # running Py3... from functools import reduce or try: from functools import reduce except ImportError: pass # it should already be in __builtins__ for pre-2.6 at the top to make sure it's in your global namespace. -tkc -- http://mail.python.org/mailman/listinfo/python-list