The scores dataset is a list of dictionaries, one of whose entries is given below for your reference:
{'SeqNo': 0, 'Name': 'Devika', 'Gender': 'F', 'City': 'Bengaluru',
'Mathematics': 85, 'Physics': 100, 'Chemistry': 79}
Write a function named group_by_city that accepts scores_dataset as argument. It should return a dictionary named cities whose keys are the names of the cities that the students are from. The value corresponding to a key (city) is the list of names of all students who hail from this city. Append the names in the order in which the students appear in the dataset.
You do not have to accept input from the user or print anything. You just have to write the definition of the function.
Example
group_by_city([{'Name': 'Lalit', 'City': 'Kanpur'},
{'Name': 'Karthik', 'City': 'Chennai'},
{'Name': 'Sapana', 'City': 'Kanpur'}])
-> {'Kanpur': ['Lalit', 'Sapana'], 'Chennai': ['Karthik']}
Implement this function:
def group_by_city(scores_dataset):
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: scores_dataset.
Input
[{'SeqNo': 0, 'Name': 'Devika', 'Gender': 'F', 'City': 'Bengaluru', 'Mathematics': 85, 'Physics': 100, 'Chemistry': 79}, {'SeqNo': 1, 'Name': 'Karthik', 'Gender': 'M', 'City': 'Chennai', 'Mathematics': 60, 'Physics': 72, 'Chemistry': 91}, {'SeqNo': 2, 'Name': 'Lalit', 'Gender': 'M', 'City': 'Kanpur', 'Mathematics': 45, 'Physics': 58, 'Chemistry': 66}, {'SeqNo': 3, 'Name': 'Sapana', 'Gender': 'F', 'City': 'Kanpur', 'Mathematics': 92, 'Physics': 88, 'Chemistry': 74}]
Output
{'Bengaluru': ['Devika'], 'Chennai': ['Karthik'], 'Kanpur': ['Lalit', 'Sapana']}