Answers for "python sum()"

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
0

python sum

x = [1,2,3,4,5]
s = sum(x)
print(s) # 15
Posted by: Guest on May-08-2021
0

python sum

from collections import Counter

x = {'both1':1, 'both2':2, 'only_x': 100 }
y = {'both1':10, 'both2': 20, 'only_y':200 }

z = dict(Counter(x)+Counter(y))

print(z)
[out]:
{'both2': 22, 'only_x': 100, 'both1': 11, 'only_y': 200}
Posted by: Guest on October-24-2021

Python Answers by Framework

Browse Popular Code Answers by Language