Sorting List by Element Length

  • Share this:

Code introduction


This function takes a list as an argument and sorts the list by the length of each element, then returns the sorted list.


Technology Stack : Built-in function sorted, list

Code Type : Function

Code Difficulty : Beginner


                
                    
def sort_list_by_length(list_to_sort):
    return sorted(list_to_sort, key=len)