At the same time, the documentation has changed ( corresponding commit ), and the current documentation, sorted explicitly, guarantees:
The built-in sorted() function is guaranteed to be stable. A variety is stable if it does not allow changing the relative order of elements being compared equal - this is useful for sorting in several passes (for example, sorting by department, then by salary class).
This piece of documentation was added in Python 2.7 and Python 3.4 (+), so any compatible implementation of this language version should have stable sorted .
Please note that for CPython list.sort been stable since Python 2.3
- Tim Peters rewrote his implementation of
list.sort() - this is "stable sorting" (equal inputs appear in the same order in the output) and faster than before.
I'm not 100% sorted , currently it just uses list.sort , but I have not checked the history for this. But most likely, he "always" used list.sort .
MSeifert May 16 '17 at 10:49 PM 2017-05-16 22:49
source share