find the sum of all values in a map in python

To find the sum of all values in a map/dictionary in Python, you can use the sum() function along with the .values() method of the dictionary. Here's an example code:

main.py
my_dict = {'a': 10, 'b': 20, 'c': 30}

# using sum() function with .values() dictionary method
total = sum(my_dict.values())

print("Sum of values in the dictionary:", total)
175 chars
7 lines

Output:

main.py
Sum of values in the dictionary: 60
36 chars
2 lines

gistlibby LogSnag