student_data is a list of dictionaries, one per student. Every dictionary has a
'rollno' key, a 'city' key, and one key per course holding the marks of that
student in the course, for example:
[{'rollno': 1, 'city': 'Chennai', 'maths': 80, 'physics': 60},
{'rollno': 2, 'city': 'Delhi', 'maths': 55, 'physics': 90}]
Write city_with_max_avg_course_mark(student_data, course) that groups the
students by city, computes the average marks in course for each city, and
returns the name of the city with the highest average. student_data is never
empty and every student has the given course. If several cities are tied, return
the one that appears first in student_data.
Example
For
[{'rollno': 1, 'city': 'Chennai', 'maths': 80}, {'rollno': 2, 'city': 'Delhi', 'maths': 90}, {'rollno': 3, 'city': 'Chennai', 'maths': 60}]
and course = 'maths', the averages are Chennai: 70.0 and Delhi: 90.0, so the
result is 'Delhi'.
Implement this function:
def city_with_max_avg_course_mark(student_data, course):
Write the function only — the arguments are read for you and the return value is printed automatically.
Arguments arrive as one Python literal per line, in this order: student_data, course.
Input
[{'rollno': 1, 'city': 'Chennai', 'maths': 80}, {'rollno': 2, 'city': 'Delhi', 'maths': 90}, {'rollno': 3, 'city': 'Chennai', 'maths': 60}]
'maths'
Output
'Delhi'