How to sort a string alphabetically in Python

Sorting a string orders its characters alphabetically. For example, sorting “cba” alphabetically results in “abc”.

Solution for How to sort a string alphabetically in Python : You can use sorted() and str.join() to sort a string alphabetically Call sorted(iterable) with a string as iterable to return a list of the characters of the string sorted alphabetically. Use str.join(iterable) with “” as str and this list as iterable to create a sorted string.


how-to-sort-a-string-alphabetically-in-python