Sorting Characters by Length in a String

  • Share this:

Code introduction


This function accepts a string as input and returns a new string with characters sorted by their length.


Technology Stack : String, sorting

Code Type : Function

Code Difficulty : Intermediate


                
                    
def sort_string_by_length(input_string):
    """
    Sorts the characters in the input string by their length.
    """
    return ''.join(sorted(input_string, key=len))                
              
Tags: