Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!ra.nrl.navy.mil!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: What does zip mean? Date: Mon, 10 Nov 2014 17:19:31 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 34 Message-ID: References: NNTP-Posting-Host: 67-130-15-94.dia.static.qwest.net X-Trace: reader1.panix.com 1415639971 23750 67.130.15.94 (10 Nov 2014 17:19:31 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 10 Nov 2014 17:19:31 +0000 (UTC) User-Agent: slrn/1.0.1 (Linux) Xref: csiph.com comp.lang.python:80475 On 2014-11-10, giacomo boffi wrote: > On 11/09/2014 11:44 AM, satishmlmlml@gmail.com wrote: >> What does zip return in the following piece of code? > > To help you understanding what is the `zip` builtin, please forget > about PKZip etc and think about the _zip fastener_ or _zipper_ in > your bag or in your trousers > > In the bag you have two sequences of teeth that the zipper > binds together in interlocking pairs No, you don't. That's not how a zipper works. Each tooth from side A, isn't bound with one from side B. It's bound with _two_ of them from side B. And each of those is in turn bound with an additional tooth from side A, and so on... > In your program you have two lists, whose elements `zip` returns > bound together in pairs What the zipper on a coat does is convert two separate sequences into a single sequence where the members alternate between the two input sequences. IOW if we want to do something analogous to a zipper fastener it should do this: zip([a,b,c,d,e,f],[1,2,3,4,5,6]) => [a,1,b,2,c,3,d,4,e,5,f,6] Item '1' is bound equally to item 'a' and 'b'. Item 'b' is bound equally to item '1' and '2'. -- Grant Edwards grant.b.edwards Yow! I joined scientology at at a garage sale!! gmail.com