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
PostgreSQLv16

Tutaj pojawi się wynik wykonania kodu

Visible tests
1
Input
"hello world"
Expected2
2
Input
" one two three "
Expected3
3
Input
""
Expected0
4
Input
"single"
Expected1
5
Input
"a b c d"
Expected4
6
Input
"a"
Expected1
Focus radio
Paused · SomaFM · Fluid