How to Sum All the Items in a Dictionary in Python


In this example, we will learn how to calculate the sum of all values in the dictionary.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

dict1 = {'a': 80, 'b': 150, 'c': 310, 'd': 169}
sumVal = sum(dict1.values())
print("The result is: ", sumVal)

Output:

The result is: 709
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments