How to sort a list of strings by length in Python

1 Answer

0 votes
lst = ['python', 'c', 'php', 'java', "c#"] 
 
lst.sort(key=len)
 
print(lst)
 
 
 
'''
run:
 
['c', 'c#', 'php', 'java', 'python']
 
'''

 



answered Jan 21, 2020 by avibootz
...