Word Counter
Counting words is useful in search, text statistics, and simple form validation. Write a function count_words that takes a string s and returns how many words it contains. Words are separated by whitespace, and there may be any number of spaces; leading and trailing spaces should not count as words.
Примеры
Ввод
"hello world"Вывод
2Ввод
" one two three "Вывод
3Ввод
""Вывод
0Нужно реализовать
def count_words(s: str) -> int:
Теги
strings
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
"hello world"Expected
22
Input
" one two three "Expected
33
Input
""Expected
04
Input
"single"Expected
15
Input
"a b c d"Expected
46
Input
"a"Expected
1Focus radio
Paused · SomaFM · Fluid