基本上我有列表(整个棕色语料库)。
dic1=brown.words()
print 'Total size of Brown Corpus :'
print len(dic1)
输出是:
Total size of Brown Corpus :
1161192
我将该列表转换为字典,使所有值为2并检查大小。
dic=dict((k,2) for k in dic1)
print 'Size of the dict:'
print len(dic)
得到了这个输出:
Size of the dict:
56057
字典包含:(key:2)
。因此,如果列表中没有单词1161192,则字典中的条目数量也应相同。为什么尺寸会发生变化?
答案 0 :(得分:7)
字典只存储不同的结果,因此当您将列表转换为字典时,会丢失任何重复的字词。