Kodewick
Start learning →
Starter←→0 / 80

Short words first

#041StarterSortingStrings3 min

The word game is over and the words get read out, shortest first. Write shortest_first(words) to return the words sorted from shortest to longest; words of the same length keep their original order. No words gives [].

Examples
shortest_first(["travel", "cat", "fish"])→['cat', 'fish', 'travel']
shortest_first([])→[]
main.py
def shortest_first(words):
    # your code here: sorted with key=len to sort by length
    ordered = words
    return ordered
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.