LearnPy Hub
← Functions problems
Hard

Sort With Your Own Key Function

Write my_sort(items, key=lambda x: x, reverse=False) using insertion sort (no sorted or .sort); equal keys keep their order. Read words and print three lines: sorted normally, sorted by length (with key), and sorted by last letter in reverse (with key and reverse=True; equal keys still keep input order).

Input

Words separated by spaces.

Output

Three lines.

Sample 1

Input
pear fig apple kiwi
Output
apple fig kiwi pear
fig pear kiwi apple
pear kiwi fig apple

Sample 2

Input
b a c
Output
a b c
b a c
c b a
solution.py
Output appears here
Sort With Your Own Key Function · Python practice problem · LearnPy Hub