Python 将两个列表转换成字典最快的方式

list1=['name','class','sex']
list2=['zhangsan','class1',1]
a = zip(list1,list2)
print(a,type(a)) # <zip object at 0x000001A2295B8808> <class 'zip'>
b = list(a)
print(b,type(b)) # [('name', 'zhangsan'), ('class', 'baoan13'), ('sex', 1)] <class 'list'>
c = dict(b)
print(c,type(c)) # {'name': 'zhangsan', 'class': 'class1', 'sex': 1} <class 'dict'>

dict1 = dict(list(zip(list1,list2))) # 可以将上面的步骤简写,归纳成一步
print(dict1)
上一篇:Java高级部分笔记之泛型


下一篇:14-6