[snip too-long subject]

Arthur ajsiegel at optonline.com
Sun Mar 21 01:30:54 CET 2004

On Sun, 21 Mar 2004 00:07:50 +0000, Garry Knight <garryknight at gmx.net>
>It might be useful to think of the items in each list coming together like
>the teeth of a zipper. But it's better than that: you're not constrained to
>two sets of teeth:
>>>> L3 = [9, 10, 11, 12]
>>>> zip(L1,L2,L3)
>[(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]

I have found zip quite useful.

But I think it is a case of Python being for consenting adults.  If
the lists are of unequal length, the first 'n' items of each list,
with 'n' being the number of items in the shortest list, are zipped.
It is assumed that is one's intention, and there is no warning that
you have attempted to zip unequal length lists.  Where the lists are
coming together from different sections of the code, are being built
dynamically, and there are corner cases to concern oneself with - well
something unexpected could be passing unless there is explicit testing
somewhere along the route.

Map behaves differently, matching None with the item in the longer
length list when the lists are of unequal length. Which I think makes
it easier to catch exceptions.

I guess I am the stage of understanding some of the not fully obvious
"traps". Sometimes, even, before I fall into them.


More information about the Python-list mailing list