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

Python Developer Medium

Python Developer — Medium

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

Key points

  • The reduce function applies a function of two arguments cumulatively to the items of a sequence
  • The initial value provided (10 in this case) is added to the result
  • The lambda function used here adds two numbers together

Ready to go further?

Related questions