ShopperCove
Menu
All writingBlogTopicsCategoriesAboutRSS
Blog
Categories
Observability & SRE62All categories
Topics
sre111localhost lab102performance70python58javascript47bundle size36benchmarking35node.js35web development21typescript19benchmark16content creation15All topics
About
Loading article…

ShopperCove

Hands-on notes on developer tools, written after the tool has actually been run.

All writingBlogCategoriesTopicsAboutPrivacyRSS

© 2026 ShopperCove

On this page

  1. What is the difference between sort() and sorted()?
  2. Is list.sort() faster than sorted()?
  3. Does sorted() use more memory?
  4. Why does list.sort() return None?
  5. How do key and reverse work with both?
  6. When should you use each?
  7. FAQ
  8. Related
  9. Sources
  1. Blog

Sort vs Sorted Python: Which One Should You Use and When?

The real differences from the Python docs, plus a 1-million-item timing and memory test we ran on Python 3.13.

30 October 2026·3 min read

Summary

Disclosure

This post contains affiliate links. If you buy through them, I may earn a commission at no extra cost to you. I only make firsthand claims about products I have actually used.

On this page
  1. What is the difference between sort() and sorted()?
  2. Is list.sort() faster than sorted()?
  3. Does sorted() use more memory?
  4. Why does list.sort() return None?
  5. How do key and reverse work with both?
  6. When should you use each?
  7. FAQ
  8. Related
  9. Sources

The sort vs sorted Python choice comes down to one question: do you want to change the list you already have, or get a new one? list.sort() sorts a list in place and returns None, while sorted() accepts any iterable and returns a new sorted list. In our test the speed was almost the same, but sorted() used more memory.

What is the difference between sort() and sorted()?

From the Python docs:

  • list.sort() is a method that only exists on lists. It changes the list in place and returns None.
  • sorted() is a built-in function. It takes any iterable (a list, tuple, string, dict, set or generator) and returns a new list. The original is left untouched.

Both take the same two keyword-only arguments, key and reverse, and both are stable, which means items that compare equal keep their original order.

nums = [5, 2, 3, 1, 4]
new = sorted(nums)   # new == [1, 2, 3, 4, 5], nums unchanged
nums.sort()          # nums == [1, 2, 3, 4, 5], returns None

Is list.sort() faster than sorted()?

Slightly, in principle. The docs say that if you do not need the original list, list.sort() is slightly more efficient. To see how much, we timed both on 1,000,000 random floats with Python 3.13.5 (best of 7 runs, each starting from the same unsorted copy):

  • list.sort() in place: 175.2 ms
  • sorted(list): 184.9 ms
  • copy the list, then sort(): 177.4 ms

That is a gap of about 5 percent on a million items. For everyday lists, pick whichever reads better; speed is not a good reason to choose.

Does sorted() use more memory?

Yes, because it builds a second list. Measured with tracemalloc on the same data:

  • list.sort(): 4.0 MB peak extra memory
  • sorted(): 12.0 MB peak extra memory

The extra 8 MB is consistent with a new list holding a million 8-byte references. If you are sorting a very large list and do not need the original order, list.sort() is the lighter choice.

Why does list.sort() return None?

The docs say this is deliberate: returning None reminds you that the method works by side effect. It also explains the classic bug:

nums = nums.sort()   # nums is now None

If you want a value back, use sorted(), or call nums.sort() on its own line.

How do key and reverse work with both?

Exactly the same way. key is a function called once per item to build the sort key, for example key=str.casefold for case-insensitive text or key=len to sort by length. reverse=True sorts in descending order. Because both are stable, you can sort in passes: sort by a secondary field first, then by the main one.

When should you use each?

  • Use sorted() when you need to keep the original, when the data is not a list, or when you want the sorted result inside an expression such as a for loop or return statement.
  • Use list.sort() when you own the list, do not need the old order and want to save memory.

FAQ

Does sorted() work on a dictionary? Yes. It returns a sorted list of the keys. In our run, sorted({"b": 1, "a": 2}) returned ['a', 'b'].

Can I sort a tuple or string in place? No. Only lists have a sort() method. sorted() works on them but always returns a list, for example sorted("cab") gives ['a', 'b', 'c'].

Is Python's sort stable? Yes. The docs guarantee that list.sort() is stable, and sorted() is too.

Related

  • sorted vs heapq vs bisect
  • Are Python dictionaries ordered?
  • What does yield do in Python?

Sources

  • 01docs.python.org/3/howto/sorting.html
  • 02docs.python.org/3/library/stdtypes.html
  • 03docs.python.org/3/library/functions.html

Lab evidence

What I found running this

Checked on 18 Oct 2026 against the official Python docs (Sorting Techniques HOWTO, list.sort() in Built-in Types, and sorted() in Built-in Functions). We also ran a real benchmark on 18 Oct 2026 with Python 3.13.5 on an 8-vCPU x86_64 Linux box: 1,000,000 seeded random floats, best of 7 runs with timeit, and peak extra memory via tracemalloc. Numbers are from that single machine and will differ on yours.

Explore the product

Freelancers and devs who want to turn coding skills into paid site builds

Turn your Python skills into paid client sites

Browse Ready Client Sites

Notes when a lab post goes up

Occasional email for new hands-on reviews. No sequence and no sponsors.

Explore the product

Freelancers and devs who want to turn coding skills into paid site builds

Turn your Python skills into paid client sites

Browse Ready Client Sites

Keep reading

  • Is typescript-eslint Strict Worth 4x Errors?

    We ran three typescript-eslint presets on a real open-source TypeScript library and counted every finding and second. The jump to strict was smaller than the jump to type-aware linting, and the findings themselves tell you whether your team is ready.

    Summary4 Nov 20267 min read

  • Python partition vs split: Which One Should You Use?

    Both cut a string at a separator, but they fail in different ways. We ran them on Python 3.13.5 to show where partition() is safer and where split() is the right tool.

    Summary2 Nov 20263 min read

  • toSorted vs sort JavaScript: Which One Copies Your Array?

    What changes when you swap sort() for toSorted(), with a real 1-million-item Node.js benchmark and the support table.

    Summary1 Nov 20263 min read