0
I'm having difficulty in sorting a list of strings in a descending order in terms of the length of words. Please help
6 Respostas
+ 1
Consider the following example
lst = ['r','ris','ri','rishi','rish']
#for ascending order
sorted(lst,key=len)
#for decending order
sorted(lst,key=len)[::-1]
+ 2
You can also do it by adding another argument to the call of sort or sorted: reverse=True
+ 1
Please mention the programming language
+ 1
Rishi Anand it worked. Thanks alot
0
If you can use this example to explain to me I'll appreciate.
Countries=["Kenya", "Australia", "Canada", "USA"]
I've been using countries.sort(key=len) to try and sort the list by length in a descending order