[Python-Dev] PEP 201, zip() builtin
Thu, 27 Jul 2000 15:45:47 -0400
[Barry A. Warsaw]
> -------------------- snip snip --------------------
> PEP: 201
> Title: Parallel Iteration
Could we please change "Parallel" to, e.g., "Lockstep" throughout? Greg
Wilson correctly pointed out that "parallel" in the context of loops means
something very different to the scientific branch of the Python community.
Easier to fix this now that after it's spread to the docs.
> However, for-loops iterate over only a single sequence, and it
> is often desirable to loop over more than one sequence, in a
> lock-step, "Chinese Menu" type of way.
Just as you realized how inappropriate "parallel" was right here <wink>.
> # find the length of the shortest sequence
> shortest = min(*map(len, args))
> shortest = min(map(len, args))
However, this implies that all sequences must tell the truth about their
lengths, but the iteration protocol actually terminates via a sequence
raising IndexError. I believe we want zip to follow the iteration protocol,
in effect breaking out of the outer loop as soon as some s[i] raises
IndexError. This was agreed to by all (incl. the BDFL) in some other year's
debates over this.
> prefers zip() due to it's Haskell heritage. See version 1.7
"its", not "it's"
> - Lazy evaluation. An earlier version of this PEP proposed that
> zip() return a built-in object that performed lazy evaluation
> using __getitem__() protocol. This has been strongly rejected
> by the BDFL in favor of returning a real Python list. If lazy
> evaluation is desired in the future, the BDFL suggests an xzip()
> function be added.
Which he'll then fight tooth and nail <wink>.
Nice job, Barry! Thank you.