Why Sorting Matters
Order makes everything easier.
Sorted data is easier to work with. You can binary search it, find duplicates next to each other, and spot the smallest and largest instantly. Sorting is so useful that computer scientists have invented dozens of ways to do it.

- Binary search needs it
- Duplicates sit together
- Dozens of ways to sort
What sorting unlocks
Once data is sorted, many problems get easy. Finding the median is just the middle item. Duplicates are neighbours. Two pointers work. And merging lists is simple. Learning how sorting works also teaches you the big ideas of algorithms, like comparing, swapping, and divide and conquer.
Sorting in Python
Python can already sort for you. Sorted returns a new sorted list, and the original is unchanged. Dot sort sorts the list in place. Reverse equals true sorts from big to small. Run it. Over the next lessons, we'll build sorting algorithms ourselves, to see what's happening inside.
nums = [5, 2, 9, 1, 7]
print(sorted(nums), nums)
nums.sort()
print(nums)
print(sorted(nums, reverse=True))[1, 2, 5, 7, 9] [5, 2, 9, 1, 7] [1, 2, 5, 7, 9] [9, 7, 5, 2, 1]
Summary
Sorting makes searching, medians, and duplicates easy. Python sorts for you, but knowing how sorting works is a core skill. Next, the simplest sort of all.
Key takeaways- sorted() makes a copy
- list.sort() is in place
- Sorting unlocks other tricks