# zip拉链功能,将两个序列一一对应,多余舍去
print(list(zip(('a','b','c'),(1,2,3,))))
print(list(zip(('a','b','c','d'),(1,2,3,))))
print(list(zip(('a','b','c'),(1,2,3,4))))
#输出结果:
#[('a', 1), ('b', 2), ('c', 3)]
#[('a', 1), ('b', 2), ('c', 3)]
#[('a', 1), ('b', 2), ('c', 3)]
p = {'name':'alex','age':18,'gender':'none'}
d = list(p.keys())
e = list(p.values())
print(list(zip(d,e)))
#输出结果:[('name', 'alex'), ('age', 18), ('gender', 'none')]
print(list(zip('hello','12345')))
#输出结果:[('h', '1'), ('e', '2'), ('l', '3'), ('l', '4'), ('o', '5')]
转载于:https://www.cnblogs.com/lhqlhq/p/8696364.html