>>>
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
傳入參數是二元可叠代對象(二元元組、列表等)時,形成對應鍵值對