[Python-Dev] PEP 201 - Parallel iteration
Barry A. Warsaw
bwarsaw@beopen.com
Tue, 18 Jul 2000 23:42:53 -0400 (EDT)
>>>>> "Gordo" == Gordon McMillan <gmcm@hypernet.com> writes:
Gordo> How about a fourth: zip(a) is the same as zip(a, []) ?
I don't like it. The way I view zip() is that the length of the
elements returned by __getitem__() should always be equal to the
number of sequences passed in as parameters. Thus it seems most
natural to me that
>>> zip((1, 2, 3))
[(1,), (2,), (3,)]
>>> zip((1, 2, 3), pad=None)
[(1,), (2,), (3,)]
When I talk about "special casing", there's two ways to look at it.
One possibility is that the implementation of zip has to explicitly
check that the number of sequences is 1 and then `do something
special' if so. To support Gordon's proposal, or the
map()-equivalent, or the raise-an-exception proposal, that would be
the case.
The second possibility is that user code must `appear' to special case
the situation when the number of sequences is exactly 1. I.e.
>>> for (i,) in zip((1, 2, 3)):
instead of the more natural (because it's less to type and because of
the map() heritage):
>>> for i in zip((1, 2, 3)):
The first example isn't really special casing though. Personally, I
think this is going to come up so infrequently that it's not worth
it.
-Barry