In this python dictionary program, we will get the sum of all the items in a dictionary.
Steps to solve the program
- Take a dictionary as input and create a variable named total and assign its value equal to 0.
- Use for loop to iterate over all the values in the dictionary using values().
- Print the output.
D1 = {'x':23,'y':10,'z':7}
total = 0
for val in D1.values():
total += val
print(total)
Output :
40