Zen of Python: Errors should never pass silently. Why does zip work the way it does?
<p>I use python's function zip a lot in my code (mostly to create dicts like below) </p>

<pre><code>dict(zip(list_a, list_b)) 
</code></pre>

<p>I find it really useful, but sometimes it frustrates me because I end up with a situation where list_a is a different length to list_b. zip just goes ahead and zips together the two lists until it achieves a zipped list that is the same length as the shorter list, ignoring the rest of the longer list. This seems like it should be treated as an error in most circumstances, which according to the zen of python should never pass silently. </p>

<p>Given that this is such an integral function, I'm curious as to why it's been designed this way? Why isn't it treated as an error if you try to zip together two lists of different lengths?</p>

<p>In my experience, the only reason that you would ever have two lists that happen to have the same length is because they were both constructed from the same source, e.g. they are <code>map</code>s of the same underlying source, they are constructed inside the same loop, etc. In these cases, rather than creating them separately and then zipping them, I usually just create a single pre-zipped list of tuples. Most of the times that I actually use zip, one of the iterables is infinite, and in these cases I'm glad that it lets me.</p>

python