content_image/816253.jpg content_image/816261.jpg
## Contents 

Guido van Rossum and the Python development team 

# Sorting HOW TO Release 3.9.5 

Python Software Foundation Email: docs@python.org 

June 01, 2021 

<img src='content_image/816253.jpg'>

<img src='content_image/816261.jpg'>

Python lists have a built-in$_{list.sort()}$ method that modifies the list in-place. There is also a$_{sorted()}$ built-in function that builds a new sorted list from an iterable. 

In this document, we explore the various techniques for sorting data using Python. 

## 1 Sorting Basics 

A simple ascending sort is very easy: just call the$_{sorted()}$ function. It returns a new sorted list: 

>>> sorted([5,2,3,1,4]) [1, 2, 3, 4, 5] 

You can also use the$_{list.sort()}$ method. It modifies the list in-place (and returns$_{None}$ to avoid confusion). 

Usually it’s less convenient than$_{sorted()}$ - but if you don’t need the original list, it’s slightly more efficient. 

