Older versions of Python (2.3 - 3.10) used an algorithm called Timsort:

Timsort is a hybrid sorting algorithm, derived from merge sort and insertion sort, designed to perform well on many kinds of real-world data. It was invented by Tim Peters in 2002 for use in the Python programming language. The algorithm finds subsets of the data that are already ordered, and uses the subsets to sort the data more efficiently. This is done by merging an identified subset, called a run, with existing runs until certain criteria are fulfilled. Timsort was Python's standard sorting algorithm from version 2.3 to version 3.10. It is now also used to sort arrays in Java SE 7, and on the Android platform.

Since 3.11, Python uses Powersort, which was designed by Ian Munro and Sebastian Wild. It is an improved nearly-optimal mergesort that adapts to existing runs of sorted data.

Answer from bgporter on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ sorting-algorithms-in-python
Sorting Algorithms in Python - GeeksforGeeks
December 12, 2025 - For example, for input [1, 4, 3, 2, 2, 1], the output should be [1, 1, 2, 2, 3, 4]. The important thing to notice is that the range of input elements is small and comparable to the size of the array.
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ howto โ€บ sorting.html
Sorting Techniques โ€” Python 3.14.6 documentation
This wonderful property lets you build complex sorts in a series of sorting steps. For example, to sort the student data by descending grade and then ascending age, do the age sort first and then sort again using grade:
Discussions

sorting - What algorithm does python's sorted() use? - Stack Overflow
In Python 2.7, how does Python's built-in sorted function work - what algorithm does it use? More on stackoverflow.com
๐ŸŒ stackoverflow.com
Is it always better to build your own sorting algorithms?
Usually you use the built in sorting algorithms. But they are good for teaching algorithm and runtime calculation. Same with trees and hash tables. More on reddit.com
๐ŸŒ r/compsci
90
168
April 25, 2021
What sorting algorithm does python used for list.sort() ??
http://www.hatfulofhollow.com/posts/code/timsort/index.html http://bugs.python.org/file4451/timsort.txt More on reddit.com
๐ŸŒ r/Python
14
40
August 11, 2009
How does Python's sort() function work?
Python sort is basically Merge Sort. However, it includes a significant preprocessing step, which involves looking for increasing/decreasing runs. This is intended to improve its efficiency on real-world data. The algorithm was implemented by Tim Peters, who named it " Timsort ". Also, a more general note. Despite the emphasis on it in algorithms courses, Quicksort and its variants are not really used that much any more. C++'s std::sort is generally implemented using Introsort, a Quicksort variant, but other than that, Merge Sort & friends dominate the world of sorting -- particularly for implementations of built-in or standard-library sorting routines. There are a couple of reasons for this. First, Quicksort is not stable. If, as in Python, a programming language has just one built-in sorting method, then it will probably be stable, as client code will sometimes need that. Second, the direction that computer architecture has taken in recent decades often improves the efficiency of Merge Sort as compared to Quicksort; even C's qsort has a Merge-Sort-based implementation these days (the one in glibc -- last I checked). More on reddit.com
๐ŸŒ r/AskComputerScience
12
32
August 12, 2020
๐ŸŒ
Real Python
realpython.com โ€บ sorting-algorithms-python
Sorting Algorithms in Python โ€“ Real Python
November 27, 2023 - The Python language, like many other high-level programming languages, offers the ability to sort data out of the box using sorted(). Hereโ€™s an example of sorting an integer array: ... You can use sorted() to sort any list as long as the values inside are comparable. Note: For a deeper dive into how Pythonโ€™s built-in sorting functionality works, check out How to Use sorted() and .sort() in Python and Sorting Data With Python. This tutorial covers two different ways to measure the runtime of sorting algorithms:
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ python_data_structure โ€บ python_sorting_algorithms.htm
Python - Sorting Algorithms
Shell Sort involves sorting elements which are away from each other. We sort a large sublist of a given list and go on reducing the size of the list until all elements are sorted.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ sorting-algorithms-in-python
Sorting Algorithms in Python
October 24, 2023 - So, whenever we swap values we set a flag to True to repeat the sorting process. If no swaps occurred, the flag would remain False and the algorithm would stop. Advice: If you'd like to read a more detailed, dedicated article on Bubble Sort, we've got you covered! With the optimization, we can implement Bubble Sort in Python as follows:
๐ŸŒ
Towards Data Science
towardsdatascience.com โ€บ home โ€บ latest โ€บ sorting algorithms โ€“ with python
Sorting Algorithms - With Python | Towards Data Science
March 5, 2025 - We continuously remove the smallest element from the unsorted segment of the list and append it to the sorted segment. We donโ€™t swap intermediate elements. Hence this algorithm sorts the array in the minimum number of swaps.
Find elsewhere
๐ŸŒ
Python
docs.python.org โ€บ 3.10 โ€บ โ€บ howto โ€บ sorting.html
Sorting HOW TO โ€” Python 3.10.20 documentation
The Timsort algorithm used in Python does multiple sorts efficiently because it can take advantage of any ordering already present in a dataset. This idiom is called Decorate-Sort-Undecorate after its three steps: First, the initial list is decorated with new values that control the sort order.
๐ŸŒ
Software Testing Help
softwaretestinghelp.com โ€บ home โ€บ python โ€บ python sort: sorting methods and algorithms in python
Python Sort: Sorting Methods And Algorithms In Python
April 1, 2025 - Most of the time the data of the ... problem. Python provides various sorting techniques for example, Bubble sort, Insertion sort, Merge sort, Quicksort, etc....
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ sorting-algorithms-explained-with-examples-in-python-java-and-c
Sorting Algorithms Explained with Examples in JavaScript, Python, Java, and C++
December 4, 2019 - Insertion sort and quick sort are in place sorting algorithms, as elements are moved around a pivot point, and do not use a separate array. Merge sort is an example of an out of place sorting algorithm, as the size of the input must be allocated ...
๐ŸŒ
4Geeks
4geeks.com โ€บ lesson โ€บ sorting-and-search-algorithms-in-python
Sorting and Searching Algorithms in Python: Optimizing Data Management
July 16, 2025 - ... In this example, we make use of a binary search algorithm to find the number 27 in a list of sorted elements, in order to find the element we are looking for, we can make use of a recursive function, in this function, the base case would ...
๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ python-sort-algorithms
Python Sort Algorithms: A Comprehensive Guide
February 6, 2024 - Python provides several built-in sorting algorithms, like the sort() function for lists, and the sorted() function for any iterable. These functions make it easy to sort data in Python.
๐ŸŒ
Towards Data Science
towardsdatascience.com โ€บ home โ€บ latest โ€บ 5 sorting algorithms in python
5 Sorting Algorithms in Python | Towards Data Science
March 5, 2025 - Figure 3 displays the algorithm in operation. ... Bubble or sinking sort repeatedly passes over the list, comparing adjacent elements. Items are swapped depending on the sorting condition. Gist 4 shows the Selection Sort Python implementation with detailed comments explaining the technique step by step.
๐ŸŒ
Stanford CS
cs.stanford.edu โ€บ people โ€บ nick โ€บ py โ€บ python-sort.html
Python Sorting
Note the "stable" feature of the sort - 'bbb' comes before 'aaa' - they have the same length, but 'bbb' was before 'aaa' in the original, so they keep that ordering in the sorted version. Say we have (str, int) "food" tuples where the int is a count, such as from a dict-count algorithm.
๐ŸŒ
Medium
medium.com โ€บ @sulthanm2d โ€บ sort-method-algorithm-in-python-359888ed8975
Sorting Algorithm in Python: Bubble Sort, Insertion Sort, and Merge Sort | by Sulthanm2d | Medium
December 14, 2023 - Bubble Sort is one of the most straightforward sorting algorithms. Its like organizing a line of people by making them swap places if theyโ€™re standing in the wrong order. Itโ€™s called โ€œbubbleโ€ because just like bubbles rising up in water, ...
๐ŸŒ
Xccelerate
xccelerate.co โ€บ blog โ€บ 6-types-of-sorting-algorithms-to-use-in-python
6 Types Of Python Sorting Algorithms | Xccelerate
July 2, 2024 - Python has an in-built sorting function that can be called using sorted(). For instance, if you have an integer array with random numbers (comparable values), here is how the algorithm would work:
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Timsort
Timsort - Wikipedia
February 17, 2026 - Implementation in Python, from PyPy commit "7fce1e5", the last update before the "Powersort" policy was incorporated. 636 lines of code, 486 of which are neither blank nor purely comments. ... {\displaystyle n} elements. In the best case, which occurs when the input is already sorted, it runs in linear time, meaning that it is an adaptive sorting algorithm.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_dsa_bubblesort.asp
Bubble Sort with Python
Imagine that the array is almost sorted already, with the lowest numbers at the start, like this for example: ... In this case, the array will be sorted after the first run, but the Bubble Sort algorithm will continue to run, without swapping elements, and that is not necessary.
๐ŸŒ
Medium
dipankarmedh1.medium.com โ€บ sorting-algorithms-in-python-1afb97238099
Mastering Sorting Algorithms with Python: A Comprehensive Guide for Data Scientists and Developers | by Dipankar Medhi | Medium
February 21, 2023 - Bubble sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order. The algorithm gets its name from the way smaller elements โ€œbubbleโ€ to the top of the list.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ fastest-way-to-sort-in-python
Fastest Way to Sort in Python - GeeksforGeeks
July 23, 2025 - Just like lists, arrays can be sorted using the sorted() function. sorted() function uses timsort algorithm which is most efficient for sorting in python.