Sorting Words by Length in Python

  • Share this:

Code introduction


This function takes a list of words as input and returns a new list where the words are sorted by their length in ascending order.


Technology Stack : list, string, sorting, key

Code Type : Function

Code Difficulty : Intermediate


                
                    
def sort_words_by_length(words):
    """
    Sorts a list of words by their length in ascending order.
    """
    return sorted(words, key=len)