Sorting Words by Length

  • Share this:

Code introduction


This function takes a list of words and returns a new list with the words sorted in ascending order based on their lengths.


Technology Stack : Built-in libraries

Code Type : Sort

Code Difficulty : Beginner


                
                    
def sort_words(words):
    """
    Sorts a list of words based on their lengths in ascending order.

    Parameters:
    words (list): A list of strings representing words to be sorted.

    Returns:
    list: A list of strings sorted by length.
    """
    return sorted(words, key=len)