Python Compute the Sum of Dictionary Values
Given a dictionary, compute the sum of all its 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
}
(
"
Sum :
"
,
returnSum
(
dict
)
)
The output of the code above is:
Sum : 600
Python3 Examples