Objective
Create a Python program that uses functools.reduce to combine all the elements of a list into a single value.
Instructions
- Import
reducefromfunctools.reduce(function, list)applies the two-argument function to the accumulated value and the next element, from left to right. - Read a line with integers (at least one) separated by spaces.
- With
reduceandlambdafunctions, compute the product, the sum and the largest (a if a > b else b). - Show
Product: P,Sum: SandLargest: Mon three lines.
2 3 4
Product: 24
Sum: 9
Largest: 4
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise