Jordan Savant # Software Engineer

Python zip iteration

Python can iterate a grouping of iterable variables like lists, dictionaries, tuples in the zip function.

It will iterate and stop at the shortest one

a = [1, 2, 3]
b = [4, 5, 6, 7, 8]
c = (9, 10, 11, 12)
d = {"a": "a", "b": "b"}

for w, x, y, z in zip(a, b, c, d):
    print("w", w)
    print(" x", x)
    print("  y", y)
    print("   z", z)
w 1
 x 4
  y 9
   z a
w 2
 x 5
  y 10
   z b