
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to sort a list of strings in Python?
To sort a list in place, i.e., sort the list itself and change ordering in that list itself, you can use sort() on the list of strings. For example,
>>> a = ["Hello", "My", "Followers"] >>> a.sort() >>> print a ['Followers', 'Hello', 'My']
If you want to keep the original list intact and instead want a new list of the sorted elements, you can use sorted(list). For Example,
>>> a = ["Hello", "My", "Followers"] >>> b = sorted(a) >>> print b ['Followers', 'Hello', 'My']
- Related Articles
- Python How to sort a list of strings
- Python – Sort by Rear Character in Strings List
- Python program to Sort a List of Strings by the Number of Unique Characters
- How to remove empty strings from a list of strings in Python?
- Python – Sort given list of strings by numeric part of string
- How to sort a Python date string list?
- Python – Sort given list of strings by part the numeric part of string
- How to sort the objects in a list in Python?
- Convert list of strings to list of tuples in Python
- Convert list of tuples to list of strings in Python
- How to sort strings in JavaScript?
- Python – To convert a list of strings with a delimiter to a list of tuple
- Python program to sort a list of tuples alphabetically
- How to create a tuple from a string and a list of strings in Python?
- Convert list of strings and characters to list of characters in Python

Advertisements