Answers for "python list reduce"

7

python reduce()

#max num in list
from functools import reduce
items = [1, 24, 17, 14, 9, 32, 2]
all_max = reduce(lambda a,b: a if (a > b) else b, items)
 
print (all_max) # 32
Posted by: Guest on May-09-2020
4

reduce in python

'''try this'''
from functools import reduce
a = [1,2,3,4]

SUM = reduce(lambda n,n2:n+n2,a)

print(SUM)
Posted by: Guest on October-15-2020
2

python reduce()

from functools import reduce
items = [1,2,3,4,5]
sum_all = reduce(lambda x,y: x + y, items)
 
print (sum_all) #15
Posted by: Guest on May-09-2020

Python Answers by Framework

Browse Popular Code Answers by Language