Editor

Sort a List of Numbers

Beginner · 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

You have a list of test scores. Print them sorted from lowest to highest, then on the next line print them sorted from highest to lowest.

Use sorted() so the original list stays unchanged.

scores = [78, 92, 65, 88, 95, 71]
# Print scores low to high
# Print scores high to low

More Sorting exercises

All Python exercises · 50 practice problems · Data Structures quiz