小编SOU*_*HIT的帖子

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

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

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,则字典中的条目数量也应相同.为什么尺寸会发生变化?

python dictionary list

0
推荐指数
1
解决办法
65
查看次数

标签 统计

dictionary ×1

list ×1

python ×1