Longest Word
Lists often need you to choose an element by some rule; here, the rule is word length. Write a function longest_word that takes a non-empty list of strings words. Return the longest word. If several words share the maximum length, return the one that appears first.
Примеры
Ввод
["a", "abc", "ab"]Вывод
"abc"Ввод
["one", "three", "two"]Вывод
"three"Ввод
["x"]Вывод
"x"Нужно реализовать
def longest_word(words: list[str]) -> str:
Теги
stringslists
Jelentkezz be a beküldési előzmények megtekintéséhez
BejelentkezésJelentkezz be az MI-mentor használatához
BejelentkezésVisible tests
1
Input
["a","abc","ab"]Expected
"abc"2
Input
["one","three","two"]Expected
"three"3
Input
["x"]Expected
"x"4
Input
["bb","aa"]Expected
"bb"5
Input
["python","is","fun"]Expected
"python"6
Input
["a"]Expected
"a"Focus radio
Paused · SomaFM · Fluid