Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80475

Re: What does zip mean?

From Grant Edwards <invalid@invalid.invalid>
Newsgroups comp.lang.python
Subject Re: What does zip mean?
Date 2014-11-10 17:19 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <m3qs33$n66$1@reader1.panix.com> (permalink)
References <baab02ae-09b4-4b9c-8e29-50e2581f9a7b@googlegroups.com> <m3qq8m$e0n$1@speranza.aioe.org>

Show all headers | View raw


On 2014-11-10, giacomo boffi <giacomo_boffi@inwind.it> 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            

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

What does zip mean? satishmlmlml@gmail.com - 2014-11-09 02:44 -0800
  Re: What does zip mean? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-09 21:58 +1100
    Re: What does zip mean? milos zorica <miloshzorica@gmail.com> - 2014-11-09 08:06 -0300
  Re: What does zip mean? giacomo boffi <giacomo_boffi@inwind.it> - 2014-11-10 17:48 +0100
    Re: What does zip mean? Grant Edwards <invalid@invalid.invalid> - 2014-11-10 17:19 +0000
      Re: What does zip mean? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-11-11 10:04 +1300
      Re: What does zip mean? Cameron Simpson <cs@zip.com.au> - 2014-11-11 07:36 +1100
      Re: What does zip mean? Terry Reedy <tjreedy@udel.edu> - 2014-11-10 19:39 -0500
      Re: What does zip mean? giacomo boffi <pecore@pascolo.net> - 2014-11-13 23:10 +0100
      Re: What does zip mean? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-14 22:06 +1100

csiph-web