Sort with a Key
Completed
Read a line of words and print them sorted by length, then alphabetically for equal lengths.
Input
One line.
Output
One line.
Example
Input
banana kiwi apple fig cherry
Output
fig kiwi apple banana cherry
Editor
Python
Hints
key=lambda w: (len(w), w) sorts by length first, then by the word.
Solution explanation
A lambda is a small anonymous function, handy for sort keys.
Show solution
words = input().split()
print(*sorted(words, key=lambda w: (len(w), w)))