同時迭代多個 可迭代物件。
測試資料:
a = [0, 1, 2]
b = [3, 4, 5]
z = zip(a, b)
# <zip object at 0x0000022E1CAECFC8>
c = list(zip(a, b))
# [(0, 3), (1, 4), (2, 5)]
d = dict(zip(a, b))
# {0: 3, 1: 4, 2: 5}
for i, j in zip(a, b):
print(f'i: {i}, j: {j}')
for i, j in dict(zip(a, b)).items():
print(f'i: {i}, j: {j}')
k, v = zip(*c)
k, v = zip(*d.items())
[list(row) for row in zip(*c)]
# [[0, 1, 2], [3, 4, 5]]