我要通过the Python NLTK book。我通过运行以下命令对“白鲸”中的单词进行了频率分布:fdist=FreqDist(text1)其中text1是“白鲸”的NLTK文本对象,即小说中单词的列表。现在我有了一个频率分布对象:
>>> fdist1
<FreqDist with 260819 outcomes>然而,列表中的许多单词都是不同大小写的相同单词,比如大小写的单词"a“:
>>> fdist1['a']
4569
>>> fdist1['A']
167如何组合这两个单词(以及每个单独列出的单词)?
发布于 2013-02-10 04:21:28
你可以创建一个新的字典,遍历FreqDict和小写key。就像这样-
lc_dict = defaultdict(int)
for (key, value) in fdist1.items():
lc_dict[key.lower()] = lc_dict[key.lower()] + valuehttps://stackoverflow.com/questions/14790927
复制相似问题