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

ishish ishish at domhain.de
Wed Aug 28 09:17:45 EDT 2013


Am 28.08.2013 13:52, schrieb AdamKal:
> Hi,
>
> 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)
>
> I looked in itertools but nothing seamed to do the job. This seams
> like something vary obvious that was needed many times elsewhere so
> maybe you could help me?

You could try somthing like:


myval = 'whatever'

for i in range(1,4):
	print eval("func%s(%s)" % (i, myval))



More information about the Python-list mailing list