I want to use lambda in python to create a function that receives functions and returns functions.

Asked 2 years ago, Updated 2 years ago, 24 views

There is a function add_functions(f,g) using Python lambda and
I want the return value to be f(x)+g(x).For example,

f=add_functions (lambdax:x*2, lambdax:x+1)

If you run f(2), the results are as follows:

f(2)#returns(2*2)+(2+1)=7

How do I write the contents of this add_functions function?
I would appreciate it if you could let me know.

The hint reads as follows:

You can directly return a lambda

python

2022-09-30 19:34

1 Answers

As the hint says, the lambda expression itself should be a return value.

default_functions(f,g):
    return lambdax —f(x)+g(x)

--From comment by metropolis.


2022-09-30 19:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.