Reverse Sort a String - Python Last Updated : 15 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The goal is to take a given string and arrange its characters in descending order based on their Unicode values. For example, in the string "geeksforgeeks", the characters will be sorted from highest to lowest, resulting in a new string like "ssrokkggfeeeee". Let's understand different methods to perform this operation efficiently.Using sorted() with reverse=TrueThis is the most straightforward way to reverse sort a string. sorted() function lets us easily sort elements and the reverse=True parameter ensures the order is descending. Python s = "geeksforgeeks" res = "".join(sorted(s, reverse=True)) print(res) Outputssrokkggfeeee Explanation:sorted() function sorts characters of the string.Adding reverse=True sorts them in descending order."".join() combines the sorted characters into a single string.Using list.sort()If we are working with a string that has been converted into a list, we can use sort() method to reverse sort it in place. This method is slightly faster for large strings as it avoids creating a new list. Python s = "geeksforgeeks" # Convert string to list and reverse sort a = list(s) a.sort(reverse=True) res = "".join(a) print(res) Outputssrokkggfeeee Explanation:list(s) converts the string s into a list of characters.a.sort(reverse=True) sorts the list a in descending order."".join(a) combines the sorted characters into a final string.Using recursionRecursion provides an unconventional approach to reverse sorting a string. It identifies the maximum character in the string repeatedly and appends it to the result. Python def fun(s): if len(s) <= 1: # Base case return s m = max(s) s = s.replace(m, "", 1) # Remove it from the string return m + fun(s) s = "geeksforgeeks" res = fun(s) print(res) Outputssrokkggfeeee Explanation:if len(s) <= 1 checks if the string s has one or fewer characters, in which case it's returned as is (base case).m = max(s) finds the maximum character in the string s.return m + fun(s) recursively calls fun(s) with the modified string and adds m to the result.Using for loopIf we want more control and prefer to manually handle the process, we can use a for loop to reverse sort a string. Python s = "geeksforgeeks" res = "" for c in sorted(s, reverse=True): res += c print(res) Outputssrokkggfeeee Explanation:sorted(s, reverse=True) sorts the string s in descending order.for c in sorted(s, reverse=True) iterates over each character in the sorted string.res += c appends each character to the result string res, which is then printed. Comment More infoAdvertise with us Next Article Reverse Sort a String - Python M manjeet_04 Follow Improve Article Tags : Python Python Programs Python string-programs Python-sort Practice Tags : python Similar Reads Python - Reversed Split Strings In Python, there are times where we need to split a given string into individual words and reverse the order of these words while preserving the order of characters within each word. For example, given the input string "learn python with gfg", the desired output would be "gfg with python learn". Let 3 min read Python - Reverse Slicing of given string Reverse slicing in Python is a way to access string elements in reverse order using negative steps.Using Slicing ([::-1])Using slicing with [::-1] in Python, we can reverse a string or list. This technique works by specifying a step of -1, which starts at the end of the sequence and moves backward, 1 min read Reverse All Strings in String List in Python We are given a list of strings and our task is to reverse each string in the list while keeping the order of the list itself unchanged. For example, if we have a list like this: ['gfg', 'is', 'best'] then the output will be ['gfg', 'si', 'tseb'].Using For LoopWe can use a for loop to iterate over th 2 min read Python | Reverse Incremental String Slicing Sometimes, while working with Python strings, we can have a problem in which we need to perform the slice and print of strings in reverse order. This can have applications in day-day programming. Let us discuss certain ways in which this task can be performed. Method #1: Using loops This is the brut 4 min read Python - Reverse Range in String List Given a string list, reverse each element of string list from ith to jth index. Input : test_list = ["Geeksforgeeks", "Best", "Geeks"], i, j = 1, 2 Output : ['ee', 'es', 'ee'] Explanation : Range of strings are extracted. Input : test_list = ["Geeksforgeeks"], i, j = 1, 7 Output : ['eeksfor'] Explan 3 min read Like