Question 15
Back to Exercise
What is the output of the following Python program?
add = lambda a: lambda b: a + b
compose = lambda f, g: lambda x: f(g(x))
inc_then_double = compose(lambda x: x * 2, add(1))
print(add(2)(3), list(map(add(10), [1, 2])), inc_then_double(5))
- A 5 [11, 12] 11
- B 6 [11, 12] 12
- C 5 [11, 12] 12 Correct
- D TypeError
Correct Answer: Option C
add(2) returns a function waiting for b. compose applies g first: add(1)(5) = 6, then doubles it to 12.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!