What is the output of the following? “`python from functools import reduce result = reduce(lambda acc, x: acc + x, [1, 2, 3, 4, 5]) print(result) “`

Python Developer Hard

Python Developer — Hard

What is the output of the following? “`python from functools import reduce result = reduce(lambda acc, x: acc + x, [1, 2, 3, 4, 5]) print(result) “`

Key points

  • The reduce function applies a function of two arguments cumulatively to the items of iterable
  • The lambda function here adds the accumulator and the current element
  • The reduce function reduces the list to a single value by applying the lambda function iteratively

Ready to go further?

Related questions