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.

Answer from Martijn Pieters on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › sorted() vs sort()
r/learnpython on Reddit: sorted() vs sort()
February 28, 2025 -

So I get that one of the main differences between sorted() and sort() is that sorted() returns a new list and sort() modifies the list directly. But I don't understand why their outputs can't be exactly equal if they print out to being, in fact, exactly equal. For example:

numbers = [3, 1, 4, 1, 5, 9, 2]

sorted_numbers = sorted(numbers)
print(f"Sorted list: {sorted_numbers}")

numbers.sort()
print(f"Sorted list: {numbers}")

print(numbers.sort() == sorted(numbers))

This is the output:

Sorted list: [1, 1, 2, 3, 4, 5, 9]
Sorted list: [1, 1, 2, 3, 4, 5, 9]
False

As we can see, both sorted(numbers) and numbers.sort return what appears to be identical output: [1, 1, 2, 3, 4, 5, 9]. Of course, sort() has modified the original list, so that object has been changed by the end of the program. But if these two outputted lists are clearly identical from a mathematical perspective (ie: [1, 1, 2, 3, 4, 5, 9] == [1, 1, 2, 3, 4, 5, 9] is true on it's on terms as a standalone expression ) - then why won't Python embrace this apparently same understanding with: print(numbers.sort() == sorted(numbers))?

Is there some unseen object that represents the original list that is lingering unprinted in the background and attached to sorted(numbers)?

Thanks ahead of time for your interest and time on this matters.

🌐
Reddit
reddit.com › r/learnpython › using sort() vs. sorted()
r/learnpython on Reddit: Using Sort() Vs. Sorted()
June 7, 2020 -

Hello all,

I am working through the Python Crash Course book and I am currently in Chapter 3 and working with lists.

I am working on some of the practice problems that require using sort() and sorted(). In one of my practice problems, it required the use of sort() to permanently sort a list in alphabetical order and also temp sort a list. I understand that sort() will alter the actual contents of the list and assume re-write how it is stored in the variable, whereas I assume sorted() is creating some type of temp variable to store the sorted list.

I am confused between how they are used in code, I was using list.sort() with no problem, but I attempted to use list.sorted() and ran into an error. I was able to correct it by changing the syntax to sorted(list). Why does sort not work in the same fashion as .sort() does?

I looked back in the chapter and saw that it refers to sort() as a method and sorted() as a function, I tried to research and learn the difference between a method and function in python and got myself even more confused. Is there an easy explanation as to why sorted(list) works but list.sorted() does not?

🌐
Reddit
reddit.com › r/python › python sort vs sorted - detailed comparison with code
r/Python on Reddit: Python sort vs sorted - Detailed Comparison With Code
April 6, 2023 -

Python sort() and sorted() are used to sort the data in ascending or descending order. Their goals are the same but are used in different conditions.

The Python sort() function is connected to the Python list and by default, sorts the list's contents in ascending order.

list.sort(reverse=False, key=None)

Python sorted() function is used to sort the iterable data. By default, this function sorts the data in ascending order.

sorted(iterable, key=None, reverse=False)

Here's a complete guide comparing both functions and pointing out differences👇👇

Python sort vs sorted - Detailed Comparison With Code

Top answer
1 of 7
445

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
69

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.

🌐
Reddit
reddit.com › r/learnpython › “sort” and “sorted” giving different results?
r/learnpython on Reddit: “Sort” and “sorted” giving different results?
August 3, 2023 -

After this code, why would x and y be different? x seems in the wrong order.

from string import lower

x='the rain in Spain stays mainly in the plain because Spain gets all the rain'.split()

y=sorted(x,key=lambda el:(x.count(el),lower(el)))

x.sort(key=lambda el:(x.count(el),lower(el)))

🌐
GeeksforGeeks
geeksforgeeks.org › python-difference-between-sorted-and-sort
Python - Difference between sorted() and sort() - GeeksforGeeks
January 17, 2024 - sort() in Python function is very similar to sorted() but unlike sorted it returns nothing and makes changes to the original sequence.
Find elsewhere
🌐
DEV Community
dev.to › trinityyi › what-is-the-difference-between-listsort-and-sorted-in-python-5a6g
What is the difference between list.sort() and sorted() in Python? - DEV Community
September 23, 2022 - On the other hand, sorted() should be used when the object to be sorted is an iterable (e.g. list, tuple, dictionary, string) and the desired outcome is a sorted list containing all elements.
🌐
DEV Community
dev.to › guzmanojero › sorted-vs-sort-in-python-whats-the-difference-2pdl
What’s the Difference between sorted() vs .sort() in Python: - DEV Community
October 14, 2025 - If you've worked with lists in Python, you've probably come across both sorted() and .sort(). At first glance, they seem to do the same thing — sort data.
🌐
Quora
quora.com › What-is-the-difference-between-sort-and-sorted-function-in-Python
What is the difference between sort() and sorted() function in Python? - Quora
Answer (1 of 5): sort() sorts the original list.sorted returns a sorted list without altering the original list. [code]a = [4,1,23,4,7,8,9] sorted(a) [1, 4, 4, 7, 8, 9, 23] print a [4, 1, 23, 4, 7, 8, 9] a.sort() [1, 4, 4, 7, 8, 9, 23] print ...
🌐
Python Engineer
python-engineer.com › posts › sort-vs-sorted
Difference between sort() and sorted() in Python - Python Engineer
Python provides two built-in functions which are sort() and sorted(). These two functions are used for sorting but come with a few differences.
🌐
Reddit
reddit.com › r/learnpython › .sort() and sorted()
.sort() and sorted() : r/learnpython
December 26, 2021 - As you can probably imagine, since both ways can be used to create a list that is sorted, the creators of Python didn't want someone to accidentally use one of these two possible paths believing that they used the other. You wouldn't want to create a sorted copy thinking that the original, unsorted list can still be used.
🌐
Scaler
scaler.com › home › topics › difference between sort and sorted in python
Difference Between Sort and Sorted in Python - Scaler Topics
October 4, 2023 - The main difference between sort and sorted in Python is that sort function returns nothing and makes changes to the original sequence, while the sorted () function creates a new sequence type containing a sorted version of the given sequence.
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › python faq
What is the difference between sort() and sorted()? - Python FAQ - Codecademy Forums
July 28, 2018 - What is the difference between them and when would I want to use one versus the other? Answer The primary difference between the list sort() function and the sorted() function is that the sort() function will modify the list it is called on.
🌐
Real Python
realpython.com › python-sort
How to Use sorted() and .sort() in Python – Real Python
February 24, 2025 - In this tutorial, you'll learn how to sort various types of data in different data structures in Python. You'll explore custom sorting orders and work with two distinct ways of sorting.
🌐
Enki
enki.com › post › what-s-the-difference-between-sort-and-sorted-in-python-dcb0b
Enki | Blog - What’s the difference between Sort and Sorted in Python
The sorted() function excels when you need to create a new sorted list without modifying the original data. It’s perfect for scenarios where data integrity is non-negotiable and you need a reliable, unaltered copy of your data. Python's versatility extends beyond just lists; its sorting capabilities can be applied to various data structures, including tuples and dictionaries.
🌐
Ducat
ducatindia.com › blog › difference-between-sort-and-sorted-in-python
What is the Difference Between sort() and sorted() in Python
Best Training Institute in Noida
sort vs sorted python - Looking for Difference Between sort and sorted in Python then read here about sort python function and sorted python function to get the difference. This institute is very nice. I am a student of MERN Full Stack. Nitin Sir is an excellent Trainer, and Nitin Sir is also an excellent Trainer for frontend. The Placement team is also very supportive in helping students get better job opportunities
Rating: 5 ​
🌐
Quora
quora.com › What-is-the-difference-between-list-sort-vs-sorted-list-in-Python
What is the difference between list.sort() vs. sorted (list) in Python? - Quora
Answer (1 of 7): I always use these as the way to explain the difference between a function and a method. sorted() is a built-in function that takes any iterable (list, tuple, dict, string, etc.) and returns a new list containing all of the items from that iterable in sorted order: [code]>>> so...