小编Kri*_*tie的帖子

为文件中的每个单词创建一个字典,并计算其后的单词的频率

我正在努力解决一个棘手的问题并迷失方向.

这是我应该做的:

INPUT: file
OUTPUT: dictionary

Return a dictionary whose keys are all the words in the file (broken by
whitespace). The value for each word is a dictionary containing each word
that can follow the key and a count for the number of times it follows it.

You should lowercase everything.
Use strip and string.punctuation to strip the punctuation from the words.

Example:
>>> #example.txt is a file containing: "The cat chased the dog."
>>> with open('../data/example.txt') as f: …
Run Code Online (Sandbox Code Playgroud)

python counter dictionary nltk n-gram

9
推荐指数
2
解决办法
3136
查看次数

标签 统计

counter ×1

dictionary ×1

n-gram ×1

nltk ×1

python ×1