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
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:
🌐
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.
🌐
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.
🌐
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.
🌐
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.
🌐
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.
🌐
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.
🌐
GitHub
github.com › TheAlgorithms › Python › wiki › Sorting-Algorithms
Sorting Algorithms · TheAlgorithms/Python Wiki · GitHub
Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order.
Author   TheAlgorithms