2019-01-17

2019-03-12  本文已影响0人  shirely大丫头

一.列表转换为字典:
1.使用zip函数:
a=[‘a1’,'a2','a3’,'a4’]
b=['b1','b2']
d=zip(a,b)
print(dict(d))
2.使用嵌套列表转换为字典:

a = ['a1','a2']
b = ['b1','b2']
c = [a,b]
print (dict(c))
dit ={}
for i inc:
dit ={}
for i in c:
dit[i[0]]=i[1]
print (dit)

上一篇 下一篇

猜你喜欢

热点阅读