在python 3里直接print zip后的结果会出现:
例如:
a = [1, 2, 3]
b = (4, 5, 6)
z = zip(a, b)
print(z)
输出:
实际上在python3里zip后的结果是一个遍历对象
正确显示法:
a = [1, 2, 3]
b = (4, 5, 6)
z = zip(a, b)
for i in z:
print(i)
输出:
(1, 4)
(2, 5)
(3, 6)
转为列表的形式:
a = [1, 2, 3]
b = (4, 5, 6)
z = zip(a, b)
z2 = list(z)
print(z2)
输出:
[(1, 4), (2, 5), (3, 6)]
再转为字典的形式:
a = [1, 2, 3]
b = (4, 5, 6)
z = zip(a, b)
z2 = list(z)
z3 = dict(z2)
print(z3)
输出:
{1: 4, 2: 5, 3: 6}