Sort with a Key

Lab Python Intermediate 20 points

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
Sample input available Sample output available
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)))
Output
Answer
HOME LEARN COMMUNITY DASHBOARD