Top Word

In text data, you often need to find the most common words, such as frequent search queries or repeated topics in reviews. Write a function most_frequent_word that receives a string text made of lowercase words separated by spaces. Return the word that appears most often. If several words are tied, choose the lexicographically smallest one.

Примеры

Ввод
"a b a c a b"
Вывод
"a"
Ввод
"the day is sunny the the the sunny is is"
Вывод
"the"
Ввод
"b a b a"
Вывод
"a"

Нужно реализовать

def most_frequent_word(text):

Теги

stringshashmapdict
PostgreSQLv16

Koodin suorituksen tulos näkyy tässä

Visible tests
1
Input
"a b a c a b"
Expected"a"
2
Input
"the day is sunny the the the sunny is is"
Expected"the"
3
Input
"b a b a"
Expected"a"
4
Input
""
Expected""
5
Input
"one"
Expected"one"
6
Input
"dog cat dog cat bird"
Expected"cat"
Focus radio
Paused · SomaFM · Fluid