Yes. Python's sort is stable: when two elements compare equal, they stay in the same relative order they had in the input. This guarantee applies to both sorted() and list.sort() and is part of the language documentation, so you can rely on it in every Python 3 version.
A Python stable sort matters because it lets you sort by several criteria in steps, keeps results predictable, and avoids surprising reordering of equal items. This article uses Python 3.13.
A sort is stable if elements with equal sort keys keep their original relative order. Imagine four records sorted by grade:
Ravi appears before Karan in the input and in the output, and Asha stays ahead of Meera. An unstable algorithm would be free to swap them. Python's implementation, called Timsort, is stable by design, so you will always see the output above.
Equal keys are common in real data: many orders share a date, many people share a city. Without stability, rerunning a sort could shuffle those ties and make a table jump around, or make tests flaky.
Stability also means the input order acts as a built-in tie-breaker. If your list is already sorted by time, sorting it by user keeps each user's items in time order, with no extra work.
The most useful consequence is that you can sort by several keys by sorting repeatedly, from the least important key to the most important one. Each later pass preserves the order produced by the earlier ones for equal keys.
The first pass puts names in alphabetical order. The second pass sorts by score, highest first, and names stay alphabetical within each score because the sort is stable. This is the standard way to mix ascending and descending order for text, where you cannot simply negate the value.
You might expect reverse=True to reverse the final list and therefore flip tied items. It does not. Python keeps equal items in their original order even with reverse=True, as if the comparison were reversed rather than the output.
a still comes before b. If you instead called sorted(...) and then list.reverse(), the tied items would flip to b, then a. Prefer the reverse argument when you want ties to stay in input order.
Timsort is a hybrid of merge sort and insertion sort, introduced in Python 2.3 and used for lists ever since. It finds already-ordered runs in the data, extends them with insertion sort, and merges runs while taking equal elements from the left run first. That merge rule is what keeps the order of equal items.
As a bonus, Timsort is very fast on data that is partly sorted: nearly sorted input takes close to O(n) time, and the worst case is O(n log n). The sort needs extra memory for merging, up to about half the list size in the worst case.
Stability applies to any sort done through sorted() and list.sort(). Other tools may differ: for example, NumPy's default np.sort uses an algorithm that is not stable unless you ask for kind="stable".
Stability is easiest to see with a table that is already in a useful order. Suppose log entries arrive in time order and you want them grouped by level without losing the time order inside each group.
Each level group still lists its entries in time order, even though the sort looked only at the level. With an unstable sort you would have to add the time to the key to get the same result. Relying on stability is fine in Python, but adding the second key explicitly makes the intent obvious to readers.
Yes. Both sorted() and list.sort() are guaranteed stable, and this is documented behaviour rather than an implementation detail.
No. Equal items keep their original order even when you pass reverse=True.
Timsort, a hybrid of merge sort and insertion sort that is stable and takes advantage of existing order in the data.
min() and max() return the first item found among equal candidates, so the earliest equal item in the iterable wins.
Python's sort is stable, so equal elements keep their input order, with or without reverse=True. Use that to sort by several criteria in passes from the least to the most important key, to get repeatable results, and to keep an earlier order as a tie-break. Timsort provides the guarantee and runs close to linear time on partly ordered data.