Skip to content Skip to sidebar Skip to footer

Call 2 Functions In A Function

The problem is as follows below: Write a function compose that takes two functions as argument, we call them Fa and Fb, and returns a function, Fres, that means that outdata from t

Solution 1:

You don't want to call either func1 or func2 yet; you just want to return a function that will call them both.

defcompose(func1, func2):
    def_(*args, **kw):
        return func1(func2(*args, **kw))
    return _

You could also just use a lambda expression to create the composed function.

defcompose(func1, func2):
    returnlambda *args, **kw: func1(func2(*args, **kw))

Solution 2:

Try this:

defcompose(func1, func2):
    defcomp(arg):
        return func1(func2(arg))
    return comp

Post a Comment for "Call 2 Functions In A Function"