Помогите пожалуйста в Python. Есть файл с каким то текстом и нужно найди самое часто встречающееся слово.
Ответы
Ответ дал:
0
Ответ:
Python 3.7.2
def readFile(file):
with open(file, 'r', encoding = 'utf-8') as file:
text = file.readlines()
return text
file = input('Enter path to file: ')
text = ' '.join(readFile(file))
most_word = ['', 0]
for word in text.split(' '):
if most_word[1] < text.count(word):
most_word[0] = word; most_word[1] = text.count(word)
print(most_word)
Приложения:
![](https://st.uroker.com/files/d16/d167f6c4fa7b9dc233ff81a76b188cea.png)
Вас заинтересует
1 год назад
1 год назад
7 лет назад
8 лет назад