Skip to main content

Python’s Built-In Sorting Algorithm

Santiago ValdarramaApril 15, 2020About 1 minPythonArticle(s)blogrealpython.compythonpy

Python’s Built-In Sorting Algorithm 관련

Sorting Algorithms in Python

In this tutorial, you'll learn all about five different sorting algorithms in Python from both a theoretical and a practical standpoint. You'll also learn several related and important concepts, including Big O notation and recursion.

Sorting Algorithms in Python
In this tutorial, you'll learn all about five different sorting algorithms in Python from both a theoretical and a practical standpoint. You'll also learn several related and important concepts, including Big O notation and recursion.

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:

array = [8, 2, 6, 4, 5]
sorted(array)
# 
# [2, 4, 5, 6, 8]

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.