Sort Words by Length in Python

  • Share this:

Code introduction


This function takes a list of words as input and returns a new list with the words sorted by their length.


Technology Stack : list, sorted, key

Code Type : Function

Code Difficulty : Intermediate


                
                    
def sort_words_by_length(words):
    """
    Sorts a list of words based on their length.
    """
    return sorted(words, key=len)                
              
Tags: