Initially, there was a dictionary in which the key is a word, meaning — how many times this word occurs in the text. It is necessary to get what word occurs most often. I tried to translate it into a list and sort it, but the list looks like this:

[(a, 3), (am, 2), (her, 1)] 

How to get exactly the word?

    1 answer 1

    For your purposes, collections.Counter is perfect:

     In [1]: text = """Изначально был словарь, в котором ключ - слово, значение - сколько раз это слово ...: стречается чаще всего. Пыталась сделать переводом в список и сортировкой, но список имеет т In [2]: from collections import Counter In [3]: c = Counter(w.lower() for w in text.split() if w.isalpha()) In [4]: c.most_common(1) Out[4]: [('в', 3)] 

    The most common word:

     In [5]: c.most_common(1)[0][0] Out[5]: 'в' 

    The 3 most common words are:

     In [6]: c.most_common(5) Out[6]: [('в', 3), ('слово', 2), ('список', 2)] 

    An alternative option is to search for such a word in the list of dictionaries:

     In [8]: items = [('a', 3), ('am', 2), ('her', 1)] In [9]: max(items, key=lambda x: x[1]) Out[9]: ('a', 3) In [10]: max(items, key=lambda x: x[1])[0] Out[10]: 'a'