Shortest Words First
Given a list of words words, sort it by word length from shortest to longest. If several words have the same length, keep them in the same relative order as in the original list. Return the sorted list.
Примеры
Ввод
["banana", "kiwi", "apple", "fig"]Вывод
["fig", "kiwi", "apple", "banana"]Ввод
["bb", "a", "cc", "d"]Вывод
["a", "d", "bb", "cc"]Ввод
[]Вывод
[]Нужно реализовать
def sort_by_length(words: list[str]) -> list[str]:
Теги
listssorting
Prihláste sa, aby ste videli históriu odoslaní
Prihlásiť saPrihláste sa, aby ste mohli používať AI mentora
Prihlásiť saVisible tests
1
Input
["banana","kiwi","apple","fig"]Expected
["fig","kiwi","apple","banana"]2
Input
["bb","a","cc","d"]Expected
["a","d","bb","cc"]3
Input
[]Expected
[]4
Input
["banana","kiwi"]Expected
["kiwi","banana"]5
Input
["fig","apple","kiwi","banana"]Expected
["fig","kiwi","apple","banana"]6
Input
["banana","kiwi","apple","fig","banana","kiwi"]Expected
["fig","kiwi","kiwi","apple","banana","banana"]Focus radio
Paused · SomaFM · Fluid