Sorting Words by Length in Python

  • Share this:

Code introduction


This function takes a list of words as an argument and returns a new list with the words sorted based on their length.


Technology Stack : Built-in libraries

Code Type : Function

Code Difficulty : Beginner


                
                    
def sort_words(words):
    """
    Sorts a list of words based on the number of letters in each word.
    """
    return sorted(words, key=len)