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 lessonYou 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
- Predict the Output: sort() vs sorted()Beginner
- Sort Words by LengthIntermediate
- Fix the Bug: Case-Sensitive SortingIntermediate
- Sort Students by GradeIntermediate
- Sort by Multiple CriteriaAdvanced
All Python exercises · 50 practice problems · Data Structures quiz