我想阅读一个文件并找到最常用的单词。以下是代码。我假设阅读文件我犯了一些错误。任何建议将不胜感激。
txt_file = open('result.txt', 'r')
for line in txt_file:
for word in line.strip().split():
word = word.strip(punctuation).lower()
all_words = nltk.FreqDist(word for word in word.words())
top_words = set(all_words.keys()[:300])
print top_words
输入result.txt文件
Musik to shiyuki miyama opa samba japan obi Musik Musik Musik
Antiques antique 1900 s sewing pattern pictorial review size Musik 36 bust 1910 s ladies waist bust