Posts

Showing posts with the label strict

How to use zip with strict argument

How to use zip with strict argument

We can use the built-in zip function to iterate over multiple iterators in parallel. If not all iterators are of the same length, the loop will terminate after the shortest iterator has been exhausted. This will happen without throwing an exception or warning. Starting with Python 3.10 zip accepts a strict argument. By default this is False. Setting strict=True will raise a ValueError if not all iterators are of the same length. The implementation is such that zip will run until it exhausts the shortest iterator and only raises an exception then.


Github gist with code

dependencies: python3.10