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 group_rollnos_by_cities(student_data) that returns a dictionary with the
city as key and the sorted list of roll numbers of the students from that city
as value. The cities appear in the order in which they are first seen in
student_data. An empty list gives an empty dictionary.
Example
For [{'rollno': 1, 'city': 'Chennai'}, {'rollno': 3, 'city': 'Delhi'}, {'rollno': 2, 'city': 'Chennai'}]
the result is {'Chennai': [1, 2], 'Delhi': [3]}.
Implement this function:
def group_rollnos_by_cities(student_data):
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.
Input
[{'rollno': 1, 'city': 'Chennai'}, {'rollno': 3, 'city': 'Delhi'}, {'rollno': 2, 'city': 'Chennai'}]
Output
{'Chennai': [1, 2], 'Delhi': [3]}