1,zip可视为对应位置打包
list1 = [1,2,3,4]
list2 = [5,6,7,8]
a = list(zip(list1,list2))
# 不把a转成list 生成的为<zip at 0x1ace257e688>
2,用于迭代
list1 = [1,2,3,4]
list2 = [5,6,7,8]
for (x,y) in zip(list1,list2):
print (x,'+',y, "=",x+y)
3,用于生成字典
k = ["a","b","c"]
v = ["1","2","3"]
dic = dict(zip(k,v))
4,字典key,value互换
k = ["a","b","c"]
v = ["1","2","3"]
dic = dict(zip(k,v))
key = dic.keys()
value = dic.values()
new_dict = dict(zip(value,key))