Python program to find the sum of all items in a dictionary

Python program to find the sum of all items in a dictionary

Given a dictionary, you might want to find the sum of all its values. Here's a simple program to achieve that:

def sum_values_in_dict(my_dict): return sum(my_dict.values()) # Example data = {'a': 100, 'b': 200, 'c': 300} print(sum_values_in_dict(data)) # Output: 600 

This program assumes that all the dictionary values are numeric. If the dictionary might contain non-numeric values, you'd need additional logic to handle or skip them.


More Tags

versioning video-capture ssl alpha-transparency check-constraints aggregation-framework navicat workflow-definition-language tableau-api crud

More Programming Guides

Other Guides

More Programming Examples