Question: Define a function named get_average(a_dict) which takes a dictionary as a parameter. The function returns a new dictionary where the keys are the same keys
Define a function named get_average(a_dict) which takes a dictionary as a parameter. The function returns a new dictionary where the keys are the same keys as the parameter dictionary but the values are the average of the list of numbers of the corresponding key. Round the average value to 2 decimal places.
For example:
| Test | Result |
|---|---|
a_dict = { 'l':[5], 's':[8], 't':[10, 3, 8, 5] } result = get_average(a_dict) for key in sorted(result.keys()): print(key, ':', result[key]) | l : 5.0 s : 8.0 t : 6.5 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
