Objective
Create a Python program that sorts the words of a sentence in two different ways using the key parameter of sorted.
Instructions
- Read a line with words separated by spaces.
- On the first line show the words sorted from shortest to longest (
key=len). - On the second line show the words sorted alphabetically by their last letter (
key=lambda w: w[-1]). - When two words tie, the order in which they appeared is kept (Python sorting is stable).
- Separate the words with a space.
sol cielo mar luna
sol mar luna cielo
luna sol cielo mar
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise