Answers for "how to order a list by the length of words fro longest to shortest"

0

how to order a list by the length of words fro longest to shortest

# Python code to sort a list without  
# creating another list Use of sort() 
def Sorting(lst): 
    lst.sort(key=len) 
    return lst 
      
# Driver code 
lst = ["rohan", "amy", "sapna", "muhammad",  
       "aakash", "raunak", "chinmoy"] 
print(Sorting(lst)) 

# Should return ['amy', 'rohan', 'sapna', 'aakash', 'raunak', 'chinmoy', 'muhammad']
Posted by: Guest on March-08-2021

Code answers related to "how to order a list by the length of words fro longest to shortest"

Python Answers by Framework

Browse Popular Code Answers by Language