这就是我现在所拥有的,这要感谢 Pavel Anossov。我正在尝试将已输出的词频转换为星号。
import sys
import operator
from collections import Counter
def candidateWord():
with open("sample.txt", 'r') as f:
text = f.read()
words = [w.strip('!,.?1234567890-=@#$%^&*()_+')for w in text.lower().split()]
#word_count[words] = word_count.get(words,0) + 1
counter = Counter(words)
print("\n".join("{} {}".format(*p) for p in counter.most_common()))
candidateWord()
这就是我现在所拥有的输出。
how 3
i 2
am 2
are 2
you 2
good 1
hbjkdfd 1
我想尝试使用的公式是最常见的单词出现 M 次,当前单词出现 N 次,打印的星号数为:
(50 * N) / M