The real differences from the Python docs, plus a 1-million-item timing and memory test we ran on Python 3.13.
3 min read
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.
From the Python docs:
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.
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):
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.
Yes, because it builds a second list. Measured with tracemalloc on the same data:
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.
The docs say this is deliberate: returning None reminds you that the method works by side effect. It also explains the classic bug:
If you want a value back, use sorted(), or call nums.sort() on its own line.
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.
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.
Lab evidence
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
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
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
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