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 sort_rollno_by_marks(student_data, course1, course2, course3) that returns
the list of roll numbers sorted in ascending order by the marks in course1,
using the marks in course2 to break ties, then the marks in course3, and
finally the roll number itself. Every student has all three courses. An empty
student_data gives an empty list.
Hint: sort with a tuple as the key.
Example
For
[{'rollno': 1, 'maths': 70, 'physics': 60, 'chem': 50}, {'rollno': 2, 'maths': 70, 'physics': 60, 'chem': 80}, {'rollno': 3, 'maths': 40, 'physics': 90, 'chem': 10}]
with course1 = 'maths', course2 = 'physics', course3 = 'chem', the result is
[3, 1, 2].
Implement this function:
def sort_rollno_by_marks(student_data, course1, course2, course3):
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, course1, course2, course3.
Input
[{'rollno': 1, 'maths': 70, 'physics': 60, 'chem': 50}, {'rollno': 2, 'maths': 70, 'physics': 60, 'chem': 80}, {'rollno': 3, 'maths': 40, 'physics': 90, 'chem': 10}]
'maths'
'physics'
'chem'
Output
[3, 1, 2]