Sort a copy. Keep the original.
Use sorted() when you want an ordered view without rearranging your source list.
The original order may tell a story.
A list can reflect the order things arrived. You might want to display those values alphabetically while keeping that arrival order available. Python’s sorted() returns a new list, leaving the original list in place.
The example stores the result under ordered. Printing both lists makes the difference visible. This is a useful habit whenever a transformation might erase information you still care about.
Two useful views
pear → apple → banana
apple → banana → pear
Choose the operation that matches your intention.
The list method .sort() changes a list in place. sorted() creates a new sorted list. Neither is universally better: the important question is whether other parts of your program still need the starting order.
Keep this exercise to simple lowercase words. Sorting mixed uppercase and lowercase text, accented names, or values of different types introduces extra choices. First make the difference between “new view” and “change the source” clear with a small predictable example.
arrival = ["pear", "apple", "banana"]
ordered = sorted(arrival)
print(ordered)
print(arrival)Make it yours.
- Run the example and compare its two lists.
- Add "apricot" at the end of arrival and rerun.
- Check that it appears alphabetically in ordered but last in arrival.
What changed when you tried it?
A little nudge
Store the return value from sorted() in a variable.
What to look for
The first list is ['apple', 'banana', 'pear']; the second remains ['pear', 'apple', 'banana']. Adding apricot changes both results while preserving arrival order in the original.
Take it one small step further
Try sorted(arrival, reverse=True) for a reversed alphabetical view.
Preserve the source when its order still means something.
Read more: Python · Sorting techniques ↗
No submission needed. This one is just for you.