Skip to content
CodeItRaw
Code Reading
/
Sorting by a Key
Path
Play
Daily
Leaderboard
tr
Predict the Output
Sorting by a Key
Sorted by length first, then alphabetically on ties. What are the first three words?
1
words = [
"kiwi"
,
"fig"
,
"banana"
,
"apple"
,
"date"
]
2
print
(
sorted
(words, key=
lambda
w: (
len
(w), w))[:
3
])