Loading...
Loading...
Loading...
A teacher has a list of students and the grade each one got. Group the names by grade.
Print one line per grade, in alphabetical order of grade, as grade: name1, name2. Sort the names inside each line alphabetically too.
Example
Input
5 Ravi B Asha A Meena B Kiran A Dev C
Output
A: Asha, Kiran B: Meena, Ravi C: Dev
Three grades, two names in A and B.
Try the problem first. Open one hint at a time.
Use the grade as the key and a list of names as the value.
setdefault(grade, []) gives the list for a grade, creating it the first time. Sort the grades and then the names when printing.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor