Technical skill practice
Python zip(): Pair Sequences and Reject Length Mismatches
Python zip groups one item from each iterable into tuples. By default it stops at the shortest iterable. Use strict=True on Python 3.10 and later when unequal lengths should be an error. A pairing iterator must be consumed before a mismatch later in the inputs can be detected.
Start with a small, explicit task
Assign owners to three fictional review tasks. First supply only two owners and inspect the truncated result. Then reject that mismatch explicitly, and finally provide all three owners for a valid assignment. No task should silently disappear from the completed report.
Run the complete example
This original example was checked with Python 3.12.14. Save it as python_zip.py and run it with Python 3.12. It uses only the standard library. The assertions check the stated results.
Expected output
[('labels', 'Ira'), ('links', 'Jin')]
length mismatch rejected
[('labels', 'Ira'), ('links', 'Jin'), ('dates', 'Kai')]
tasks = ["labels", "links", "dates"]
owners = ["Ira", "Jin"]
truncated = list(zip(tasks, owners))
assert truncated == [("labels", "Ira"), ("links", "Jin")]
try:
list(zip(tasks, owners, strict=True))
except ValueError:
mismatch = "length mismatch rejected"
else:
raise AssertionError("expected strict mismatch")
complete = list(zip(tasks, owners + ["Kai"], strict=True))
assert complete[-1] == ("dates", "Kai") and len(complete) == 3
print(truncated)
print(mismatch)
print(complete)
Explain the result
The default call produces two pairs and omits dates because it has no corresponding owner. The result looks well formed, so inspecting tuple shapes alone would not detect the missing task. Consuming the strict iterator raises ValueError when it discovers the unequal input lengths.
The final call provides the missing owner and checks all three pairs. This is positional pairing: it assumes the owner sequence is already in the intended task order. Equal lengths cannot prove correct identity matching. For real records linked by IDs, join by those identifiers rather than treating length equality as a complete data-integrity check.
Avoid these mistakes
Creating zip(..., strict=True) alone does not inspect every input immediately. Also consider partial side effects if a loop processes some pairs before discovering the mismatch. For a small assignment batch, materializing the pairs first can validate the lengths before downstream updates; large streams need a deliberate processing policy.
Questions, answered
Does zip pad a shorter sequence?
No. The default result stops at the shortest input rather than filling a missing owner.
Which Python versions support strict=True?
It is available from Python 3.10; this exact example was checked with 3.12.14.
Sources and examples
ResumizeAI team. Examples are fictional teaching material, not customer results. Replace sample details with your own facts.
Your experience. A complete resume.
Build in Resumize with ATS-friendly templates, guided editing and a live preview. Start free, then upgrade when you need more.
Free account required. Free-plan PDF exports include a watermark.