Reverse Sort a String - Python Last Updated : 12 Jul, 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 M manjeet_04 Follow Improve Article Tags : Python Python Programs Python string-programs Python-sort Explore Python FundamentalsPython Introduction 3 min read Input and Output in Python 4 min read Python Variables 5 min read Python Operators 5 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 7 min read Python Functions 5 min read Recursion in Python 6 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 5 min read Python Tuples 4 min read Dictionaries in Python 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 6 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 2 min read Python MySQL 9 min read Python Packages 12 min read Python Modules 7 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 11 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 6 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 15+ min read StatsModel Library- Tutorial 4 min read Learning Model Building in Scikit-learn 8 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 7 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 7 min read Python | Build a REST API using Flask 3 min read How to Create a basic API using Django Rest Framework ? 4 min read Python PracticePython Quiz 3 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like