为什么在Python中将列表转换为字典时大小会发生变化

SOU*_*HIT 0 python dictionary list

基本上我有列表(整个棕色语料库).

dic1=brown.words()
print 'Total size of Brown Corpus :'
print len(dic1)
Run Code Online (Sandbox Code Playgroud)

输出是:

Total size of Brown Corpus :
1161192
Run Code Online (Sandbox Code Playgroud)

我将该列表转换为字典,使所有值为2并检查大小.

dic=dict((k,2) for k in dic1)
print 'Size of the dict:'
print len(dic)
Run Code Online (Sandbox Code Playgroud)

得到了这个输出:

Size of the dict:
56057
Run Code Online (Sandbox Code Playgroud)

该词典包含:(key:2).因此,如果列表中没有单词1161192,则字典中的条目数量也应相同.为什么尺寸会发生变化?

Osc*_*ith 7

字典只存储不同的结果,因此当您将列表转换为字典时,您将丢失任何重复的字词.