Fix the Bug: Case-Sensitive Sorting
Intermediate · Fix the bug · 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 lessonThe code below tries to sort names alphabetically, but uppercase and lowercase names are mixing incorrectly. Fix the sort so it works in true alphabetical order regardless of case.
The output should be: ['alice', 'Bob', 'Charlie', 'dave', 'Eve']
names = ['Charlie', 'alice', 'Eve', 'dave', 'Bob']
result = sorted(names)
print(result)
More Sorting exercises
- Sort a List of NumbersBeginner
- Predict the Output: sort() vs sorted()Beginner
- Sort Words by LengthIntermediate
- Sort Students by GradeIntermediate
- Sort by Multiple CriteriaAdvanced
All Python exercises · 50 practice problems · Data Structures quiz