Python program to find the sum of all in a dictionary
In this example shows, We have declared the dictinary with keys and values,get the values using value() method,print the sum of all using sum() method.
Example.py
items={ 'a':47, 'b':253, 'c':100, 'd':500 } print("Dictionary: ", items) print("Sum of Dictionary values is: ",sum(items.values()))
- values() method : Extracts all values from the dictionary.
- sum() function : Adds all the values together.
Output
Dictionary: {'a': 47, 'b': 253, 'c': 100, 'd': 500} Sum of Dictionary values is: 900