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.
def compose(func1, func2):
def _(*args, **kw):
return func1(func2(*args, **kw))
return _
You could also just use a lambda
expression to create the composed function.
def compose(func1, func2):
return lambda *args, **kw: func1(func2(*args, **kw))
Solution 2:
Try this:
def compose(func1, func2):
def comp(arg):
return func1(func2(arg))
return comp
Post a Comment for "Call 2 Functions In A Function"