我正在编写一个 Python 程序,我需要计算文本文件中每个单词的数量。
def count_words(word,d):
for l in word:
if l in d:
d[l] += 1
else:
d[l] = 1
return d
def count_letters():
d = dict()
word_file = open('w.txt')
for line in word_file:
word = line.strip();
d = count_words(word,d)
return d