PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchUse sorted(words) to create a new alphabetically ordered list, or words.sort() to reorder a list in place. For case-insensitive sorting, pass key=str.casefold to either method.
Choose between a new list and sorting in place
Python provides two built-in options. sorted() accepts any iterable and returns a new list, leaving the original sequence unchanged. list.sort() changes the existing list and returns None. The Python Sorting HOW TO explains both behaviors.
| What you need | Use | What happens |
|---|---|---|
| Keep the original unchanged, or sort an iterable such as a tuple | sorted(items) |
Returns a new list |
| Reorder an existing list | items.sort() |
Mutates the list; returns None |
Make a sorted copy
Call sorted() when you want the result in a separate list:
words = ["pear", "apple", "banana"]
alphabetical = sorted(words)
print(alphabetical) # ['apple', 'banana', 'pear']
print(words) # ['pear', 'apple', 'banana']
Reorder the existing list
Call .sort() when changing the list itself is intended:
#1 Best Overall
words = ["pear", "apple", "banana"]
words.sort()
print(words) # ['apple', 'banana', 'pear']
Do not assign the method’s return value back to the list: words = words.sort() makes words equal to None.
Sort strings without distinguishing uppercase and lowercase
Default string sorting distinguishes uppercase and lowercase. To compare strings without that distinction, use the built-in str.casefold method as the key:
Rank #2
names = ["Zoe", "alice", "Émile"]
case_insensitive = sorted(names, key=str.casefold)
print(case_insensitive) # ['alice', 'Zoe', 'Émile']
The key determines what Python compares; it does not replace the original strings. A key is calculated once per item during sorting. You can use the same option with .sort():
names.sort(key=str.casefold)
Sort in descending order
Pass reverse=True to put the sorted result in descending order. It works with both sorting methods and can be combined with a key:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minutereverse_order = sorted(names, key=str.casefold, reverse=True)
Python’s sort is stable: when items have equal sort keys, their relative order from the input is preserved. This is useful, for example, when a key intentionally treats differently cased strings as equivalent.
Sort records by a name field
For objects with a name attribute, use a key that selects that attribute. For tuples with the name in the first position, use an item accessor:
people_by_name = sorted(people, key=lambda person: person.name)
rows_by_name = sorted(rows, key=operator.itemgetter(0))
These examples assume the selected values can be compared with one another. A key changes the comparison basis while leaving the stored objects or records intact.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.When language-specific alphabetization matters
Case-insensitive sorting is not the same as dictionary ordering in every language. If the ordering must follow a particular locale’s rules, Python’s sorting guide describes using locale.strxfrm() as a key or locale.strcoll() as a comparison function. These functions follow the active locale, so the application needs to set the intended locale for its environment. See the Python Sorting HOW TO for details.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Best Value
Handle values that cannot be compared directly
The examples above assume strings, or selected key values, are mutually orderable. If a list contains mixed or otherwise unorderable values, provide an explicit key that maps every item to a comparable value; without one, Python may raise a TypeError.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




