211k views
1 vote
Calculate maximum average Suppose we have a small student dictionary. The dictionary contains the name of each student as key and value is a list of their score for three courses. Sample dictionary is provided in the template file. student_dict

User Anowar
by
7.4k points

1 Answer

0 votes

Answer:

from functools import reduce

from collections import Counter

def cal_max_avg( mydict ):

new_item = [ ]

for items in mydict.items():

reducer = reduce(lambda x,y: x + y, items[1])/3

new_item.append((items[0], reducer))

newdict = Counter(dict(new_item))

return newdict.most_common(1)

diction = {'john': [45,54,56], 'yolanda':[98,78,87], 'Joshua':[67,78,87]}

result = cal_max_avg( diction )

Step-by-step explanation:

The python function accepts a dictionary and returns a tuple of the key from the input dictionary with the maximum average score for the students.

User Harsukh Makwana
by
7.8k points