How To Sort A List Of Words By Length
I want to sort words in a list based on length. The test case is {'cat','jump','blue','balloon'} When run through this method it will print something along the lines of: {'balloon'
Try this. It will sort the list based on length of strings in ascending order
list_name.sort(key=len)
For descending order,
list_name.sort(key=len,reverse=True)
Post a Comment for "How To Sort A List Of Words By Length"