How to sum dictionary values in Python

2 Answers

0 votes
dict = {'key1':34, 'key2':89, 'key3':12, 'key4':72, 'key5':90}

print(sum(dict.values()))

    
    
    
'''
run:

297

'''

 



answered Apr 11, 2021 by avibootz
0 votes
dict = {'key1':34, 'key2':89, 'key3':12, 'key4':72, 'key5':90}

summ = 0

for val in dict.values():
    summ += val
    
print(summ)

    
    
    
'''
run:

297

'''

 



answered Apr 11, 2021 by avibootz
...