How to Make zip Raise an Error for Lists of Different Lengths with strict=True
zip() pairs up items from two lists, but when one list is shorter it simply stops, and the extra items vanish without any message. When the lists should always match, that silence hides a bug. strict=True turns it into an error. This guide shows both on Python 3.15.2.
Syntax
zip(<list_a>, <list_b>, strict=True)
| Part | What it means |
|---|---|
<list_a>, <list_b> | The lists to pair up, item by item |
strict=True | Raise a ValueError if one list runs out before the others |
The Python documentation recommends it: "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."
The Example
Three names but only two ages: an age is missing. The script pairs them first without strict, then with it.
Prerequisites
- uv and Python 3.10 or later, the version that added
strict. This guide uses uv 0.13.10 with Python 3.15.2, in a project made withuv init.
Step 1: Write the Script
names = ["Ada", "Grace", "Linus"]
ages = [36, 45]
print(list(zip(names, ages)))
print(list(zip(names, ages, strict=True)))

Step 2: Run It
uv run python strict.py
[('Ada', 36), ('Grace', 45)]
Traceback (most recent call last):
File "/Users/you/source/python-basics/strict.py", line 5, in <module>
print(list(zip(names, ages, strict=True)))
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: zip() argument 2 is shorter than argument 1
![The terminal after uv run python strict.py: [('Ada', 36), ('Grace', 45)] without Linus, then a ValueError: zip() argument 2 is shorter than argument 1 from the strict line.](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/programming/python/2026/python-zip-strict-02-output.webp)
The first line shows the quiet behaviour: Linus is gone, and nothing says so. The second line stopped with ValueError: zip() argument 2 is shorter than argument 1: argument 2 is ages, and it ran out first. The command works unchanged in PowerShell.
When the second list is the longer one, the message says so: zip([1, 2, 3], [1, 2, 3, 4], strict=True) raised ValueError: zip() argument 2 is longer than argument 1.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Using plain zip for lists that must match | A missing item silently drops a row of your result | Add strict=True |
Expecting strict=True to fill in the missing items | It only raises an error | To pad the shorter list instead, use itertools.zip_longest() |
FAQ
When does the error happen?
When the loop reaches the end of the shorter list, not when zip is called: zip is lazy. The pairs before that point have already been produced.
Is there a way to fill the gaps instead of failing?
Yes: the documentation says shorter iterables "can be padded with a constant value to make all the iterables have the same length. This is done by itertools.zip_longest()."
Conclusion
Without strict, zip dropped Linus without a word. With strict=True, the same lists raised ValueError: zip() argument 2 is shorter than argument 1, which is what you want when the lists are supposed to match.
