如果只是添加一次,
>>>
l
=
['01',
'张三']
>>>
dic
=
{}
>>>
dic[l[0]]
=
l[1]
如果有大量的这种二元列表要添加到字典中,那么
>>>
data
=
[['01',
'张三'],
['02',
'李四'],
['03',
'None']]
>>>
dic
=
dict(data)
输入
>>>help(dict)
可以看到如下解释:
dict(iterable)
->
new
dictionary
initialized
as
if
via:
|
d
=
{}
|
for
k,
v
in
iterable:
|
d[k]
=
v
传入参数是二元可迭代对象(二元元组、列表等)时,形成对应键值对