Sort Students by Grade
Intermediate · Write the code · from Python Sorting: sort(), sorted(), Key Functions, and Custom Order
From the lesson: Python Sorting: sort(), sorted(), Key Functions, and Custom Order
Imagine your bookshelf at home. Books are scattered everywhere - some by title, some by color, some shoved in sideways. Finding anything takes forever.
Read the lessonSort the list of students by their grade from highest to lowest. Print each student's name and grade on a separate line in the format: Name: Grade
students = [
{'name': 'Alice', 'grade': 88},
{'name': 'Bob', 'grade': 95},
{'name': 'Charlie', 'grade': 72},
{'name': 'Diana', 'grade': 91},
]
# Sort by grade (highest first) and print each student
More Sorting exercises
- Sort a List of NumbersBeginner
- Predict the Output: sort() vs sorted()Beginner
- Sort Words by LengthIntermediate
- Fix the Bug: Case-Sensitive SortingIntermediate
- Sort by Multiple CriteriaAdvanced
All Python exercises · 50 practice problems · Data Structures quiz