Editor

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 lesson

Sort 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

All Python exercises · 50 practice problems · Data Structures quiz