Write a Python program to sum all the items in a dictionary


The program creates a dictionary d with four key-value pairs. The values method is used to extract the values of the dictionary as a list. The sum function is then used to calculate the sum of the values in the list. Finally, the result of the sum is printed using the print function. In summary, the program demonstrates how to calculate the sum of the values in a dictionary in Python by using the values method and the sum function.

Source Code

d = {1:23,2:45,3:-17,4:87}
print(sum(d.values()))

Output


138