
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
Python program to find the sum of all items in a dictionary
In this article, we will learn about the solution to the problem statement given below.
Problem statement − We are given a dictionary, and we need to print the 3 highest value in a dictionary.
Three approaches to the problem statement are given below:
Approach 1 − Calculating sum from the dictionary iterable
Example
# sum function def Sum(myDict): sum_ = 0 for i in myDict: sum_ = sum_ + myDict[i] return sum_ # Driver Function dict = {'T': 1, 'U':2, 'T':3, 'O':4, 'R':5} print("Sum of dictionary values :", Sum(dict))
Output
Sum of dictionary values : 14
Approach 2 − Calculating the sum from the dictionary.values() iterable
Example
# sum function def Sum(dict): sum_ = 0 for i in dict.values(): sum_ = sum_ + i return sum_ # Driver Function dict = {'T': 1, 'U':2, 'T':3, 'O':4, 'R':5} print("Sum of dictionary values :", Sum(dict))
Output
Sum of dictionary values : 14
Approach 3 − Calculating the sum from the dictionary.values() iterable
Example
# sum function def Sum(dict): sum_ = 0 for i in dict.keys(): sum_ = sum_ + dict[i] return sum_ # Driver Function dict = {'T': 1, 'U':2, 'T':3, 'O':4, 'R':5} print("Sum of dictionary values :", Sum(dict))
Output
Sum of dictionary values : 14
Conclusion
In this article, we have learned how we can find the highest 3 values in a dictionary
- Related Articles
- Python Program to Multiply All the Items in a Dictionary
- Python program to find the sum of dictionary keys
- Program to find sum of the sum of all contiguous sublists in Python
- Python Program to Find the Sum of all Nodes in a Tree
- Program to find sum of all elements of a tree in Python
- Python Program to Find the Sum of All Nodes in a Binary Tree
- Program to find sum of beauty of all substrings in Python
- Program to find the sum of all digits of given number in Python
- Program to find sum of all odd length subarrays in Python
- Program to find sum of the 2 power sum of all subarray sums of a given array in Python
- Program to find XOR sum of all pairs bitwise AND in Python
- Python program to find sum of absolute difference between all pairs in a list
- Python program to find the highest 3 values in a dictionary
- How to sum values of a Python dictionary?
- Program to find number of items left after selling n items in python

Advertisements