Sum of dictionary values

EasyDictionary Programs · 16 of 94

Write a Python program to add up all the values of a dictionary.

Advertisement
Input
{"x": 23, "y": 10, "z": 7}
Output
40

Approach

  1. sum(d.values()).

Solution

Python
print(sum({"x": 23, "y": 10, "z": 7}.values()))
Output
40

Learn the concept

New to this topic? Read the lesson, then come back.

More dictionary programs

← All 94 Dictionary Programs