Solution Review : Average of Values of Keys in a Dictionary
This lesson will explain how to find an average of values of keys' values in a dictionary.
We'll cover the following
Solution: Use the sum()
and len()
function
- Use the
sum(dictionary.values())
function to calculate the sum of values in a dictionary. - Use
len(dictionary)
to calculate the length of dictionary, then divide the sum by length to calculate the average.
This concept is demonstrated by the following python code.
Get hands-on with 1200+ tech skills courses.