On Apr 25, 2020, at 09:40, Christopher Barker <pythonchb@gmail.com> wrote:
- The main exception to this may be when one of them is infinite, but how common is that, really? Remember that when zip was first created (py2) it was a list builder, not an iterator, and Python itself was much less iterable-focused.
Well, yes, and improvements like that are why Python 3.9 is a better language than Python 2.0 (when zip was first added). Python wasn’t just much less iterable-focused, it didn’t even have the concept of “iterable”. While it did have map and filter, the tutorial taught you to loop over range(len(xs)), only mentioning map and filter as “good candidates to pass to lambda forms” for people who really want to pretend Python is Lisp rather than using it properly. Adding the iterator protocol and more powerful for loop; functions like zip, enumerate, and iter; generators, comprehensions, and generator expressions; itertools; yield from; and changing map and friends to iterators is a big part of why you can write all kinds of things naturally in Python 3.9 that were clumsy, complicated, or even impossible. Sure, you can use it as if it were Python 2.0 but with Unicode, but it’s a lot more than that. But also, why was zip added with “shortest” behavior in 2.0 in the first place? It wasn’t to support infinite or otherwise lazy lists, because those didn’t exist. And it wasn’t chosen on a whim. In Python 1.x, if you knew your lists were the same length, you used map with None as the function. (Well, usually you just looped over range(len(first_list)), but if you wanted to be all Lispy, you used map.) But if you didn’t know the lists were the same length, you couldn’t (because map had “longest” behavior, with an unchangeable fillvalue of None, until 3.0). If that didn’t actually come up for people even in Python 1.x, nobody would have asked for it in 2.0.