Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

sorted multiple keys python

a_list = ["aaa", "cc", "bb"]

new_list = sorted(a_list, key=lambda x: (len(x), x))
#Sort by length then alphabetically

print(new_list)
#OUTPUT
#>>['bb', 'cc', 'aaa']
Source by www.adamsmith.haus #
 
PREVIOUS NEXT
Tagged: #sorted #multiple #keys #python
ADD COMMENT
Topic
Name
3+9 =