Easy Tutorial
❮ Ref Random Randrange Python Conversion Binary Octal Hexadecimal ❯

Python Calculate Sum of Dictionary Values

Python3 Examples

Given a dictionary, calculate the sum of all numeric values.

Example

def returnSum(myDict): 

    sum = 0
    for i in myDict: 
        sum = sum + myDict[i] 

    return sum

dict = {'a': 100, 'b':200, 'c':300} 
print("Sum :", returnSum(dict))

Executing the above code outputs:

Sum : 600

Python3 Examples

❮ Ref Random Randrange Python Conversion Binary Octal Hexadecimal ❯