
05.01.2022, 01:00
|
|
Новичок
Регистрация: 29.11.2015
Сообщений: 14
Провел на форуме: 5175
Репутация:
0
|
|
Господа , поделитесь python скриптиком или тулзой для получения отсортированного списка частоты встречи слова в файле, например:
vasya:35
olya:23
nina:12
olga:5
В ExTDv088 этот функционал нерабочий.
Такой скрипт есть, но не знаю как туда сортировку вкорячить:
FILE_NAME = '1.txt'
wordCounter = {}
with open(FILE_NAME,'r') as fh:
for line in fh:
# Replacing punctuation characters. Making the string to lower.
# The split will spit the line into a list.
word_list = line.replace(',','').replace('\'','').replace('.', '').lower().split()
for word in word_list:
# Adding the word into the wordCounter dictionary.
if word not in wordCounter:
wordCounter[word] = 1
else:
# if the word is already in the dictionary update its count.
wordCounter[word] = wordCounter[word] + 1
print('{:15}{:3}'.format('Word','Count'))
print('-' * 18)
# printing the words and its occurrence.
for (word,occurance) in wordCounter.items():
print('{:15}{:3}'.format(word,occurance))
|
|
|