Reduce

Գրեք reduce կոչվող ֆունկցիա, որը ֆունկցիան կվերցնի որպես առաջին արգումենտ, զանգվածը՝ որպես երկրորդ արգումենտ, իսկ սկզբնական արժեքը՝ որպես երրորդ արգումենտ: reduce ֆունկցիան պետք է վերադարձնի մեկ արժեք, որը ստացվում է այն ցուցակի բոլոր տարրերի վրա կիրառելուց հետո:
def reduce():
	...

print(reduce(lambda total, item: total + item, [1, 2, 3, 4], 0))     # 10
print(reduce(lambda total, item: total + item, [1, 2, 3, 4], 4))     # 14
print(reduce(lambda total, item: total * item, [1, 2, 3, 4], 1))     # 24
print(reduce(lambda total, item: max(total, item), [1, 2, 3, 4], 0)) # 4
print(reduce(lambda total, item: min(total, item), [1, 2, 3, 4], 0)) # 0
print(reduce(lambda total, item: min(total, item), [1, 2, 3, 4], 5)) # 1
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue