I was working on a Python project where I needed to display a list of U.S. cities in alphabetical order. It seemed like a simple task, but I quickly realized there were multiple ways to do it efficiently in Python.
As someone who has been developing in Python for over ten years, I’ve seen many beginners struggle with sorting lists, especially when they involve strings with different cases or custom sorting needs.
In this tutorial, I’ll show you three simple and practical ways to sort a list alphabetically in Python. We’ll go step by step, using real-world examples that you can try right away.
Method 1 – Use the sort() Method in Python
The easiest and most direct way to sort a list alphabetically in Python is by using the built-in sort() method. This method sorts the list in place, meaning it modifies the original list instead of creating a new one.
Here’s a simple example where I sort a list of U.S. states alphabetically.
states = ["Texas", "california", "New York", "florida", "Alaska"]
# Sort the list alphabetically (case-sensitive)
states.sort()
print("Sorted list (case-sensitive):", states)
# Sort the list alphabetically ignoring case
states.sort(key=str.lower)
print("Sorted list (case-insensitive):", states)You can refer to the screenshot below to see the output.

In the first sort() call, Python sorts the list based on Unicode values, which means all uppercase letters come before lowercase ones. That’s why Alaska appears before california.
To make sorting case-insensitive, I used the key=str.lower argument. This ensures that all items are compared in lowercase, giving a more natural alphabetical order.
Method 2 – Use the sorted() Function in Python
While sort() modifies the original list, the sorted() function returns a new sorted list without changing the original one. This is useful when you want to keep your original list intact.
Here’s how I use it in real projects when I need both the original and sorted versions.
cities = ["Chicago", "boston", "Atlanta", "Denver", "seattle"]
# Create a new sorted list (case-sensitive)
sorted_cities = sorted(cities)
print("Original list:", cities)
print("Sorted list (case-sensitive):", sorted_cities)
# Create a new sorted list (case-insensitive)
sorted_cities_case_insensitive = sorted(cities, key=str.lower)
print("Sorted list (case-insensitive):", sorted_cities_case_insensitive)You can refer to the screenshot below to see the output.

In the example above, you can see that the original list of cities remains unchanged. This is one of the biggest advantages of using sorted() when you need to preserve your data.
When working on data pipelines or APIs, I often prefer sorted() because it’s safer and doesn’t mutate the original data source.
Method 3 – Sort a List of Dictionaries Alphabetically in Python
Sometimes, your data might not be a simple list of strings. You might have a list of dictionaries, for example, a list of U.S. cities with population data.
In such cases, you can still sort alphabetically by specifying a custom key function.
cities_data = [
{"city": "Houston", "population": 2300000},
{"city": "Phoenix", "population": 1600000},
{"city": "Austin", "population": 980000},
{"city": "Boston", "population": 675000},
]
# Sort alphabetically by city name
sorted_cities_data = sorted(cities_data, key=lambda x: x["city"].lower())
for city in sorted_cities_data:
print(city)You can refer to the screenshot below to see the output.

Here, I used a lambda function as the key to tell Python which dictionary field to sort by, in this case, the “city” key.
The .lower() ensures that the sorting is case-insensitive. This is a common pattern when working with structured data such as JSON or API responses.
Method 4 – Sort a List in Reverse Alphabetical Order in Python
Sometimes, you might want to sort your list in reverse order, for example, when displaying the latest entries first or ranking data from Z to A.
Python makes this very easy using the reverse=True parameter.
states = ["Nevada", "California", "Oregon", "Washington", "Idaho"]
# Sort alphabetically in reverse order
states.sort(reverse=True)
print("Reverse alphabetical order:", states)You can also use the same parameter with the sorted() function:
# Using sorted() to reverse sort
reverse_sorted_states = sorted(states, reverse=True)
print("Reverse sorted states:", reverse_sorted_states)This is one of my favorite Python tricks when I need quick control over the sorting direction without writing extra logic.
Method 5 – Sort a List Alphabetically with Mixed Data Types in Python
In some real-world cases, your list might contain a mix of strings and numbers. For example, you might have a list of product codes like this:
items = ["Item10", "Item2", "Item1", "Item11", "Item5"]
# Sort alphabetically (default behavior)
sorted_items = sorted(items)
print("Alphabetically sorted items:", sorted_items)You can refer to the screenshot below to see the output.

At first glance, this might not give the result you expect because Python sorts these values lexicographically (i.e., character by character). So “Item10” comes before “Item2”.
To fix this, you can use a custom key function that extracts the numeric part for natural sorting.
import re
def natural_sort_key(item):
return [int(text) if text.isdigit() else text.lower() for text in re.split(r'(\d+)', item)]
items = ["Item10", "Item2", "Item1", "Item11", "Item5"]
sorted_items = sorted(items, key=natural_sort_key)
print("Naturally sorted items:", sorted_items)This approach is extremely useful when sorting filenames, product IDs, or any strings that include numbers.
Method 6 – Sort a List Alphabetically Using Locale Settings
If you’re dealing with international data (for example, city names with accents), Python’s default sorting might not always handle it correctly.
You can use the locale module to sort strings according to specific language rules.
import locale
# Set locale to U.S. English
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
cities = ["Zürich", "Århus", "New York", "Chicago"]
# Sort using locale rules
sorted_cities = sorted(cities, key=locale.strxfrm)
print("Locale-aware sorted cities:", sorted_cities)Using locale.strxfrm() ensures that words with special characters are sorted properly according to the language’s alphabetical rules.
When to Use sort() vs. sorted() in Python
Here’s a quick summary based on my experience:
| Method | Modifies Original List | Returns New List | Best Use Case |
|---|---|---|---|
sort() | ✅ Yes | ❌ No | When you don’t need the original list |
sorted() | ❌ No | ✅ Yes | When you want to preserve the original list |
If I’m working with temporary data, I use sort(). But if I’m writing production code where data integrity matters, I always go with sorted().
Practical Tip
When sorting text data in Python, always consider case sensitivity and locale. For most English datasets, key=str.lower works perfectly. But if you’re handling multilingual text, use the locale module for accurate results.
Conclusion
So, that’s how you can easily sort a list alphabetically in Python. We covered multiple methods, from the basic sort() and sorted() functions to advanced techniques like sorting dictionaries, mixed data, and locale-aware sorting.
Sorting is one of those small but powerful Python skills that make your code cleaner, faster, and more readable. Whether you’re sorting U.S. city names, product lists, or large datasets, these methods will help you handle it efficiently.
You may also like to read:
- How to Initialize a Dictionary with Default Values
- Python Dictionary Find Key By Value
- Convert Dict_Values to List in Python
- Python Dictionary of Lists

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.