
Sorting Algorithms in Python
Sorting Algorithms in Python 관련

Watch Now
This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding:
Sorting is a basic building block that many other algorithms are built upon. It’s related to several exciting ideas that you’ll see throughout your programming career. Understanding how sorting algorithms in Python work behind the scenes is a fundamental step toward implementing correct and efficient algorithms that solve real-world problems.
In this tutorial, you’ll learn
- How different sorting algorithms in Python work and how they compare under different circumstances
- How Python’s built-in sort functionality works behind the scenes
- How different computer science concepts like recursion and divide and conquer apply to sorting
- How to measure the efficiency of an algorithm using Big O notation and Python’s
timeit
module
By the end of this tutorial, you’ll understand sorting algorithms from both a theoretical and a practical standpoint. More importantly, you’ll have a deeper understanding of different algorithm design techniques that you can apply to other areas of your work. Let’s get started!








Conclusion
Sorting is an essential tool in any Pythonista’s toolkit. With knowledge of the different sorting algorithms in Python and how to maximize their potential, you’re ready to implement faster, more efficient apps and programs!
In this tutorial, you learned:
- How Python’s built-in
sort()
works behind the scenes - What Big O notation is and how to use it to compare the efficiency of different algorithms
- How to measure the actual time spent running your code
- How to implement five different sorting algorithms in Python
- What the pros and cons are of using different algorithms
You also learned about different techniques such as recursion, divide and conquer, and randomization. These are fundamental building blocks for solving a long list of different algorithms, and they’ll come up again and again as you keep researching.
Take the code presented in this tutorial, create new experiments, and explore these algorithms further. Better yet, try implementing other sorting algorithms in Python. The list is vast, but selection sort, heapsort, and tree sort are three excellent options to start with.
Watch Now
This tutorial has a related video course created by the Real Python team. Watch it together with the written tutorial to deepen your understanding:
