137 views

1 Answer

1 1 vote

The $\texttt{reduce()}$ function repeatedly applies the lambda function and carries forward one accumulated value.

Here, the initial accumulator value is $1$.

lambda acc, x: acc * x + 1

Step-by-step:

Initial acc = 1

x = 2: acc = 1 * 2 + 1 = 3
x = 3: acc = 3 * 3 + 1 = 10
x = 4: acc = 10 * 4 + 1 = 41

Therefore:

ans = 41

The output is:

41
Answer:
Position:
Show:

Related questions

1 1 vote
1 1 answer
122
122 views
GO Classes asked Jun 22
122 views
Consider the following Python code:nums = [1, 2, 3, 4, 5] mapped = list(map(lambda x: x * x if x % 2 else x + 10, nums)) filtered = list(filter(lambda x: x % 3 == 0 or x ...
2 2 votes
1 1 answer
109
109 views
GO Classes asked Jun 22
109 views
Consider the following Python code:a = "GATE" b = [10, 20] c = range(3) z = list(zip(a, b, c)) print(z, len(z))What is the output of the code above?[('G', 10, 0), ('A', 2...
2 2 votes
1 1 answer
99
99 views
GO Classes asked Jun 22
99 views
Consider the following Python code:letters = ["A", "B", "C"] numbers = [1, 2, 3] pairs = list(zip(letters, numbers)) print(pairs , pairs[-1][0] + str(pairs[0] ))What is t...
0 0 votes
1 1 answer
101
101 views
GO Classes asked Jun 22
101 views
Consider the following Python code:def fun(a, *numbers): print(a, numbers, len(numbers)) return a + sum(numbers[:2]) print(fun(10, 20, 30, 40))What is the output of the c...