๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-sort-a-string
Python Program to Sort a String - GeeksforGeeks
July 11, 2025 - sorted() function is the most efficient way to sort a string. It returns a sorted list of characters which we can then join back into a single string. This method is concise and efficient as it uses Python's built-in functions.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how to sort a string alphabetically?
r/learnpython on Reddit: How to sort a string alphabetically?
February 13, 2021 -

If I have a string "cab", I want to sort the string alphabetically to get "abc". The sorted() function returns a list instead of a string. For example, I tried the following:

str = "cab"
sorted_str = sorted(str)
print(sorted_str)

and it prints ['a', 'b', 'c'] instead of 'abc'. I can use a for loop to create another string like this and it prints 'abc', but it's cumbersome:

new_sorted_str = ''
for i in range(len(sorted_str)):
    new_sorted_str += sorted_str[i]
print(new_sorted_str) 

Is there a better way?

.

๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_sorted.asp
Python sorted() Function
Remove List Duplicates Reverse ... Python Bootcamp Python Certificate Python Training ... The sorted() function returns a sorted list of the specified iterable object....
๐ŸŒ
Google
developers.google.com โ€บ google for education โ€บ python โ€บ python sorting
Python Sorting | Python Education | Google for Developers
The key function takes in 1 value ... sort. For example with a list of strings, specifying key=len (the built in len() function) sorts the strings by length, from shortest to longest....
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ howto โ€บ sorting.html
Sorting Techniques โ€” Python 3.14.4 documentation
February 23, 2026 - The list.sort() method and the functions sorted(), min(), max(), heapq.nsmallest(), and heapq.nlargest() have a key parameter to specify a function (or other callable) to be called on each list element prior to making comparisons.
๐ŸŒ
Stanford CS
cs.stanford.edu โ€บ people โ€บ nick โ€บ py โ€บ python-sort.html
Python Sorting
>>> sorted(strs, reverse=True) ['zebra', 'donut', 'banana', 'apple'] By default in Python, uppercase chars come before lowercase chars, so uppercase strings will sort to the front of the list:
๐ŸŒ
Real Python
realpython.com โ€บ python-sort
How to Use sorted() and .sort() in Python โ€“ Real Python
February 24, 2025 - Just like before, you can use sorted() to iterate through each element of the iterable you pass in. In a string, each element means each character, including spaces. Note: Python sorts strings lexicographically by comparing Unicode code points ...
Find elsewhere
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ how to sort a string in python?
How to Sort a String in Python | Analytics Vidhya
October 17, 2024 - To sort a string using this approach, we can convert the string into a list of characters, sort the list using the sort() method, and then join the sorted characters back into a string.
๐ŸŒ
Replit
replit.com โ€บ home โ€บ discover โ€บ how to sort a string in python
How to sort a string in Python | Replit
February 13, 2026 - Here, youโ€™ll find several techniques to sort strings, with practical tips, real-world applications, and debugging advice to help you master string manipulation for your specific use cases. text = "python" sorted_text = ''.join(sorted(text)) print(sorted_text)--OUTPUT--hnopty
๐ŸŒ
datagy
datagy.io โ€บ home โ€บ python posts โ€บ python strings โ€บ python: sort a string (4 different ways)
Python: Sort a String (4 Different Ways) โ€ข datagy
December 19, 2022 - Learn how to use Python to sort a string including how to sort strings using the sorted function, with case sensitivity or insensitivity.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ how to sort list of strings in python
How to Sort List of Strings in Python - Spark By {Examples}
May 31, 2024 - To sort a list of strings in Python you can use the sort() method. This method will order the list of strings in place, meaning that it will modify the original list and you wonโ€™t need to create a new list.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ sort a string in python
Sort a String in Python - Scaler Topics
April 7, 2024 - The sorted() function in Python returns a "sorted list" of the given iterable (list,tuple,set,etc.) object. We can also specify ascending or descending order in our function. The join() method takes all items in an iterable (list,tuple,set,etc.) ...
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Sort a List of Numeric Strings in Python | note.nkmk.me
January 31, 2024 - In Python, you can sort a list with the sort() method or the sorted() function. Sort a list, string, tuple in Python (sort, sorted) This article explains how to sort a list of numeric strings and a li ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-how-to-sort-a-list-of-strings
How to sort a list of strings in Python - GeeksforGeeks
July 11, 2025 - The sorted() function returns a new sorted list containing all the items from the original list. ... Strings are sorted lexicographically (dictionary order).
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ examples โ€บ alphabetical-order
Python Program to Sort Words in Alphabetic Order
To understand this example, you should have the knowledge of the following Python programming topics: ... In this example, we illustrate how words can be sorted lexicographically (alphabetic order). # Program to sort alphabetically the words form a string provided by the user my_str = "Hello this Is an Example With cased letters" # To take input from the user #my_str = input("Enter a string: ") # breakdown the string into a list of words words = [word.lower() for word in my_str.split()] # sort the list words.sort() # display the sorted words print("The sorted words are:") for word in words: print(word)
๐ŸŒ
Tutorials Freak
tutorialsfreak.com โ€บ python-tutorial โ€บ examples โ€บ sort-strings-python
How to Sort String in Python? (With & Without Sort Function)
Learn how to sort strings in Python. This tutorial provides examples and a step-by-step guide for beginners to effectively sort strings in various ways
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Sort a List, String, Tuple in Python: sort, sorted | note.nkmk.me
August 17, 2023 - In Python, there are two ways to sort a list in ascending or descending order: the sort() method and the built-in sorted() function. To sort a string (str) or tuple, use sorted(). Sort a list using th ...