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
Logáil isteach chun stair na n-aighneachtaí a fheiceáil
Logáil isteachLogáil isteach chun an Meantóir IS a úsáid
Logáil isteachVisible 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