Is there a particular reason for your big-O requirements? Or do you just want it to be fast? The sortedcontainers module is pure-Python and fast (as in fast-as-C implementations like blist and rbtree).

The performance comparison shows it benchmarks faster or on par with blist's sorted list type. Note also that rbtree, RBTree, and PyAVL provide sorted dict and set types but don't have a sorted list type.

If performance is a requirement, always remember to benchmark. A module that substantiates the claim of being fast with Big-O notation should be suspect until it also shows benchmark comparisons.

Disclaimer: I am the author of the Python sortedcontainers module.


Installation:

pip install sortedcontainers

Usage:

>>> from sortedcontainers import SortedList
>>> l = SortedList()
>>> l.update([0, 4, 1, 3, 2])
>>> l.index(3)
3
>>> l.add(5)
>>> l[-1]
5
Answer from GrantJ on Stack Overflow
🌐
Python documentation
docs.python.org › 3 › howto › sorting.html
Sorting Techniques — Python 3.14.7 documentation
A simple ascending sort is very easy: just call the sorted() function. It returns a new sorted list: ... You can also use the list.sort() method. It modifies the list in-place (and returns None to avoid confusion).
🌐
Grant Jenks
grantjenks.com › docs › sortedcontainers › sortedlist.html
Sorted List — Sorted Containers 2.4.0 documentation
Sorted Containers is an Apache2 licensed Python sorted collections library, written in pure-Python, and fast as C-extensions. The introduction is the best way to get started. ... Sorted list is a sorted mutable sequence.
Discussions

Does python have a sorted list? - Stack Overflow
I am not sure how Python implements lists exactly, but my bet would be that they are stored in contiguous memory (certainly not as a linked list). If that is indeed so, the insertion using bisect which you demonstrate will have complexity O(n). ... Sadly not out the box. But Grant Jenk's sortedcontainers ... More on stackoverflow.com
🌐 stackoverflow.com
Sorting lists in python: sorted() vs sort()
sorted() is functional and .sort() is an instance method. Functions should preferably not modify input parameters while object method would be expected to modify act on the instance. Edit: I know that my statement doesn't hold true in all instances, but when making your own functions and methods it's a good way to implement it like described. Documentation is key as always. More on reddit.com
🌐 r/Python
32
904
May 16, 2022
python - Pythonic way to check if a list is sorted or not - Stack Overflow
SapphireSun is quite right. You can just use lst.sort(). Python's sort implementation (TimSort) check if the list is already sorted. If so sort() will completed in linear time. More on stackoverflow.com
🌐 stackoverflow.com
python - What is the difference between sorted(list) vs list.sort()? - Stack Overflow
list.sort() sorts the list and replaces the original list, whereas sorted(list) returns a sorted copy of the list, without changing the original list. When is one preferred over the other? Which i... More on stackoverflow.com
🌐 stackoverflow.com
🌐
W3Schools
w3schools.com › python › ref_list_sort.asp
Python List sort() Method
Remove List Duplicates Reverse ... Python Study Plan Python Interview Q&A Python Training ... The sort() method sorts the list ascending by default....
🌐
W3Schools
w3schools.com › python › ref_func_sorted.asp
Python sorted() Function
Remove List Duplicates Reverse ... Study Plan Python Interview Q&A Python Training ... The sorted() function returns a sorted list of the specified iterable object....
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-sorted-function
Python sorted() Function - GeeksforGeeks
December 20, 2025 - sorted() function in Python returns a new sorted list from the elements of any iterable, such as a list, tuple, set, or string.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-sorted-containers-an-introduction
Python sorted containers - GeeksforGeeks
July 12, 2025 - 1. SortedList: It is a special type of list from the sortedcontainers module. It automatically maintains the order of its elements, meaning that each time you add or remove an element, the list remains sorted.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-check-if-list-is-sorted-or-not
Check if a List is Sorted or not - Python - GeeksforGeeks
For the list a = [1, 2, 3, 4, 5], we are checking for ascending order and here all() method is used verify if each element is less than or equals to its next element in the list. It only returns True if the list is sorted in ascending order.
Published: March 5, 2026
🌐
PyPI
pypi.org › project › sortedcontainers › 1.5.3
sortedcontainers · PyPI
Python’s standard library is great until you need a sorted collections type. Many will attest that you can get really far without one, but the moment you really need a sorted list, dict, or set, you’re faced with a dozen different implementations, most using C-extensions without great ...
🌐
Medium
medium.com › did-you-know-the-journal-blog › list-sort-vs-sorted-list-aab92c00e17
list.sort() vs. sorted(list). A closer look at Python’s built-in List… | by Florian Dahlitz | Medium
January 9, 2020 - However, keep in mind that list.sort is only implemented for lists, whereas sorted accepts any iterable. Furthermore, if you use list.sort, you will lose your original list. I hope this article revealed you more insights into the Python programming language.
🌐
Codecademy
codecademy.com › article › how-to-sort-a-list-in-python
How to sort a list in Python | Codecademy
Python provides two built-in methods for sorting lists: sort() and sorted().
🌐
Yasoob Khalid
yasoob.me › 2016 › 04 › 24 › python-sorted-collections
Python Sorted Collections - Yasoob Khalid
April 24, 2016 - It’s Python 2 and Python 3 compatible. It’s fast. It’s fully-featured. And it’s extensively tested with 100% coverage and hours of stress. SortedContainers includes SortedList, SortedDict, and SortedSet implementations with a familiar API. >>> from sortedcontainers import SortedList, SortedDict, SortedSet >>> values = SortedList('zaxycb') >>> values[0] 'a' >>> values[-1] 'z' >>> list(values) # Sorted order is automatic.
🌐
Towards Data Science
towardsdatascience.com › home › artificial intelligence › sorting lists in python
Sorting Lists in Python | Towards Data Science
October 23, 2020 - The sort() method has two optional parameters: the key parameter and reverse parameter. The key parameter takes in a function that takes a single argument and returns a key to use for sorting. By default, the sort() method will sort a list of numbers by their values and a list of strings alphabetically...
🌐
Codecademy
codecademy.com › article › how-to-sort-lists-of-lists-in-python
How to Sort Lists of Lists in Python (With Examples) | Codecademy
Learn how to sort lists of lists in Python using `sorted()`, `list.sort()`, `lambda`, and key functions with examples.
Top answer
1 of 7
447

sorted() returns a new sorted list, leaving the original list unaffected. list.sort() sorts the list in-place, mutating the list indices, and returns None (like all in-place operations).

sorted() works on any iterable, not just lists. Strings, tuples, dictionaries (you'll get the keys), generators, etc., returning a list containing all elements, sorted.

  • Use list.sort() when you want to mutate the list, sorted() when you want a new sorted object back. Use sorted() when you want to sort something that is an iterable, not a list yet.

  • For lists, list.sort() is faster than sorted() because it doesn't have to create a copy. For any other iterable, you have no choice.

  • No, you cannot retrieve the original positions. Once you called list.sort() the original order is gone.

2 of 7
70

What is the difference between sorted(list) vs list.sort()?

  • list.sort mutates the list in-place & returns None
  • sorted takes any iterable & returns a new list, sorted.

sorted is equivalent to this Python implementation, but the CPython builtin function should run measurably faster as it is written in C:

def sorted(iterable, key=None):
    new_list = list(iterable)    # make a new list
    new_list.sort(key=key)       # sort it
    return new_list              # return it

When is one preferred over the other?

  • Use list.sort when you do not wish to retain the original sort order (Thus you will be able to reuse the list in-place in memory.) and when you are the sole owner of the list (if the list is shared by other code and you mutate it, you could introduce bugs where that list is used.)
  • Use sorted when you want to retain the original sort order or when you wish to create a new list that only your local code owns.

Can a list be reverted to the unsorted state after list.sort() has been performed?

No - unless you made a copy yourself, that information is lost because the sort is done in-place.

Which is more efficient? By how much?

To illustrate the penalty of creating a new list, use the timeit module, here's our setup:

import timeit
setup = """
import random
lists = [list(range(10000)) for _ in range(1000)]  # list of lists
for l in lists:
    random.shuffle(l) # shuffle each list
shuffled_iter = iter(lists) # wrap as iterator so next() yields one at a time
"""

And here's our results for a list of randomly arranged 10000 integers, as we can see here, we've disproven an older list creation expense myth:

Python 2.7

>>> timeit.repeat("next(shuffled_iter).sort()", setup=setup, number = 1000)
[3.75168503401801, 3.7473005310166627, 3.753129180986434]
>>> timeit.repeat("sorted(next(shuffled_iter))", setup=setup, number = 1000)
[3.702025591977872, 3.709248117986135, 3.71071034099441]

Python 3

>>> timeit.repeat("next(shuffled_iter).sort()", setup=setup, number = 1000)
[2.797430992126465, 2.796825885772705, 2.7744789123535156]
>>> timeit.repeat("sorted(next(shuffled_iter))", setup=setup, number = 1000)
[2.675589084625244, 2.8019039630889893, 2.849375009536743]

After some feedback, I decided another test would be desirable with different characteristics. Here I provide the same randomly ordered list of 100,000 in length for each iteration 1,000 times.

import timeit
setup = """
import random
random.seed(0)
lst = list(range(100000))
random.shuffle(lst)
"""

I interpret this larger sort's difference coming from the copying mentioned by Martijn, but it does not dominate to the point stated in the older more popular answer here, here the increase in time is only about 10%

>>> timeit.repeat("lst[:].sort()", setup=setup, number = 10000)
[572.919036605, 573.1384446719999, 568.5923951]
>>> timeit.repeat("sorted(lst[:])", setup=setup, number = 10000)
[647.0584738299999, 653.4040515829997, 657.9457361929999]

I also ran the above on a much smaller sort, and saw that the new sorted copy version still takes about 2% longer running time on a sort of 1000 length.

Poke ran his own code as well, here's the code:

setup = '''
import random
random.seed(12122353453462456)
lst = list(range({length}))
random.shuffle(lst)
lists = [lst[:] for _ in range({repeats})]
it = iter(lists)
'''
t1 = 'l = next(it); l.sort()'
t2 = 'l = next(it); sorted(l)'
length = 10 ** 7
repeats = 10 ** 2
print(length, repeats)
for t in t1, t2:
    print(t)
    print(timeit(t, setup=setup.format(length=length, repeats=repeats), number=repeats))

He found for 1000000 length sort, (ran 100 times) a similar result, but only about a 5% increase in time, here's the output:

10000000 100
l = next(it); l.sort()
610.5015971539542
l = next(it); sorted(l)
646.7786222379655

Conclusion:

A large sized list being sorted with sorted making a copy will likely dominate differences, but the sorting itself dominates the operation, and organizing your code around these differences would be premature optimization. I would use sorted when I need a new sorted list of the data, and I would use list.sort when I need to sort a list in-place, and let that determine my usage.

🌐
LearnPython.com
learnpython.com › blog › sort-alphabetically-in-python
How to Sort a List Alphabetically in Python | LearnPython.com
We want to sort this list and store it as a new variable called sorted_list. In Python, sorting a list alphabetically is as easy as passing a list of strings to the sorted() method.