在python2.6中构造一个dict,含100个条目,key为'1','2',...,'100',value任意

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 10:10:26
在python2.6中构造一个dict,含100个条目,key为''1'',''2'',...,''100'',value任意在python2.6中构造一个dict,含100个条目,key为''1'',''2'',...

在python2.6中构造一个dict,含100个条目,key为'1','2',...,'100',value任意
在python2.6中构造一个dict,含100个条目,key为'1','2',...,'100',value任意

在python2.6中构造一个dict,含100个条目,key为'1','2',...,'100',value任意
>>> dict_info={}
>>> for item in range(1,101):
...dict_info[item]=1
...
>>> len(dict_info)
100
>>> dict_info.keys()
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,
23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,
43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,
63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,
83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100]
>>>

{str(i):None for i in range(1,101)}

d = {}
for i range(100):
d[str(i)] = i

a = {}
[a.setdefault(str(i), '') for i in xrange(1, 101)]