每天CookBook之Python-067
xpts = [1, 5, 4, 2, 10, 7]
ypts = [101, 78, 37, 15, 62, 99]
for x, y in zip(xpts, ypts):
print(x, y)
a = [1, 2, 3]
b = ['w', 'x', 'y', 'z']
for i in zip(a, b):
print(i)
from itertools import zip_longest
for i in zip_longest(a, b):
print(i)
for i in zip_longest(a, b, fillvalue=0):
print(i)
headers = ['name', 'shares', 'price']
values = ['ACME', 100, 490.1]
s = dict(zip(headers, values))
print(s)
a = [1, 2, 3]
b = [10, 11, 12]
c = ['x', 'y', 'z']
for i in zip(a, b, c):
print(i)
out
1 101
5 78
4 37
2 15
10 62
7 99
(1, 'w')
(2, 'x')
(3, 'y')
(1, 'w')
(2, 'x')
(3, 'y')
(None, 'z')
(1, 'w')
(2, 'x')
(3, 'y')
(0, 'z')
{'name': 'ACME', 'price': 490.1, 'shares': 100}
(1, 10, 'x')
(2, 11, 'y')
(3, 12, 'z')