sorted() and list.sort()

Python's built-in sorts: sorted() returns a new sorted list from any iterable, and list.sort() sorts a list in place.

In more detail

Both are stable, O(n log n) in the worst case and much faster on partly ordered data. Both accept key= to sort by a computed value and reverse=True for descending order. Use list.sort() when you no longer need the original order and want to save memory.

Related terms

Taught in

References