Python Practice › Dictionary Programs › Program 16
Sum of dictionary values
Write a Python program to add up all the values of a dictionary.
Input
{"x": 23, "y": 10, "z": 7}Output
40
Approach
sum(d.values()).
Solution
print(sum({"x": 23, "y": 10, "z": 7}.values()))Output
40
Learn the concept
New to this topic? Read the lesson, then come back.