Python zip(): How to Loop Over Lists Together

If you have two lists that belong together, like names and scores, Python zip() is the tool that walks through them side by side. This guide explains what Python zip does, shows short examples you can run, and covers the uneven-list trap that catches a lot of new developers. Facts come from the official Python documentation for Python 3.15.2, checked December 2, 2026.

VetBoss is not affiliated with, endorsed by or sponsored by the Python Software Foundation.

What zip() does, in the docs' own words

The official Python docs describe it in one line: "Iterate over several iterables in parallel, producing tuples with an item from each one." (Python docs: zip)

Two terms in that sentence are worth knowing. An iterable is anything you can loop over: a list, a tuple, a string, a range. A tuple is a small, fixed group of values written inside parentheses.

Here is the simplest example:

names = ['Ortiz', 'Kim', 'Brooks']
scores = [91, 84, 77]

for pair in zip(names, scores):
    print(pair)

That prints three tuples: ('Ortiz', 91), then ('Kim', 84), then ('Brooks', 77).

In real code you will usually unpack each pair straight into two variables, which reads better:

for name, score in zip(names, scores):
    print(name, score)

The same docs page offers a helpful picture: zip() "turns rows into columns, and columns into rows."

Why use it instead of an index counter

Without zip(), people coming from other languages tend to write a loop over index numbers:

for i in range(len(names)):
    print(names[i], scores[i])

That works, but it gives you more to get wrong. An off-by-one mistake, or a list you forgot to update, can slip through. zip() says exactly what you mean: take these together, one row at a time.

zip() is lazy

zip() does not build a list right away. The docs say "zip() is lazy: The elements won't be processed until the iterable is iterated on, e.g. by a for loop or by wrapping in a list."

So if you print zip(names, scores) directly, you see a zip object, not your data. Wrap it in list() to look inside:

print(list(zip(names, scores)))

One more detail: a zip object can be used once. After you loop through it, it is empty. If you need the pairs twice, store them with list() first.

The uneven-list trap

This is the part that bites people. If your lists are different lengths, zip() quietly stops at the shorter one. In the docs' words, "By default, zip() stops when the shortest iterable is exhausted." It will "ignore the remaining items in the longer iterables".

names = ['Ortiz', 'Kim', 'Brooks', 'Nguyen']
scores = [91, 84, 77]
print(list(zip(names, scores)))

Nguyen is dropped, and Python raises no error.

That silence can hide a real bug. The docs warn that without the strict option, "any bug that results in iterables of different lengths will be silenced, possibly manifesting as a hard-to-find bug in another part of the program."

strict=True makes mismatches loud

The docs note "Changed in version 3.10: Added the strict argument." With it, zip() raises an error instead of dropping data:

list(zip(names, scores, strict=True))

That line raises a ValueError and tells you which argument ran long.

The docs also say zip() "is often used in cases where the iterables are assumed to be of equal length. In such cases, it's recommended to use the strict=True option."

If two lists are supposed to match, use strict=True. A crash while you are testing is much easier to deal with than a wrong report that nobody notices.

If you truly want to keep the extra items, the standard library's itertools module has a version that pads the shorter side with a fill value instead.

Planning your next career step? Check your eligibility.

Three everyday uses

1. Build a dictionary from two lists.

fields = ['name', 'rank', 'unit']
values = ['Kim', 'SSG', 'HHC']
record = dict(zip(fields, values))

Now record['rank'] gives you 'SSG'.

2. Compare two lists item by item.

planned = [10, 12, 8]
actual = [10, 11, 8]
for p, a in zip(planned, actual, strict=True):
    if p != a:
        print('Mismatch:', p, a)

That pattern helps any time you check a plan against what actually happened, like a packing list against an inventory count.

3. Unzip pairs back into separate groups. The docs show that zip() together with the star operator "can be used to unzip a list":

pairs = [('Ortiz', 91), ('Kim', 84)]
names, scores = zip(*pairs)

This gives you tuples back, not lists. Wrap each one in list() if you need to change them later.

Common mistakes

  • Printing the zip object. Wrap it in list() when you want to see the contents.
  • Looping over the same zip twice. The second loop gets nothing.
  • Trusting uneven data. Use strict=True when lengths should match.
  • Forgetting it takes more than two. zip(a, b, c) gives three-item tuples.
  • Expecting lists back when unzipping. You get tuples.

Where this fits in a developer's skill set

zip() is a small function, but it teaches a habit that matters in real work: making code say what it means and fail loudly when the data is wrong. Python's own site says Python "can be easy to pick up whether you're a first time programmer or you're experienced with other languages." (Python.org About)

If you are just starting, the posts on whether Python is hard to learn and how long it takes to learn Python are good next reads. If AI work is your goal, see Python for AI.

Where VetBoss fits

Step Into Tech is VetBoss's AI Engineer path, in two stages. Stage 1, Full Stack Developer, covers HTML and CSS, JavaScript, Python, React JS, Certified GPT and MySQL, in live instructor-led classes with hands-on projects. Stage 2 is the apprenticeship part of the path and is not open yet: Join waiting list. See Step Into Tech.

Your next step

VetBoss exists to serve veterans, and you can reach the team directly.

Thank you for reading, and thank you for your service. VetBoss serves veterans, and the team is glad to hear from you.

You came here for Python zip(). If you have served and are starting to think about what comes after service, let's map out what comes next. Our military skills translator is a place to start.

Book an eligibility call, or call 855-VET-BOSS (855-838-2677).

Previous
Previous

How Many Times Can You Take the ASVAB? The Official Retest Rules

Next
Next

What Is West Point?