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


Groups > comp.lang.python > #80420

Re: What does zip mean?

References <baab02ae-09b4-4b9c-8e29-50e2581f9a7b@googlegroups.com> <545f48b9$0$13005$c3e8da3$5496439d@news.astraweb.com>
Date 2014-11-09 08:06 -0300
Subject Re: What does zip mean?
From milos zorica <miloshzorica@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.15595.1415531192.18130.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

sorry my bad

On Sun, Nov 9, 2014 at 7:58 AM, Steven D'Aprano <
steve+comp.lang.python@pearwood.info> wrote:

> satishmlmlml@gmail.com wrote:
>
> > What does zip return in the following piece of code?
>
> Have you read the Fine Manual?
>
> In Python 2, zip returns a list:
>
> zip(['a', 'b', 'c'], [1, 2, 3])
>
> => [('a', 1), ('b', 2), ('c', 3)]
>
> https://docs.python.org/2/library/functions.html#zip
>
>
> In Python 3, zip does the same, except instead of a list, it returns a
> special iterator which produces the items on demand rather than in advance.
>
> https://docs.python.org/3/library/functions.html#zip
>
>
>
> > curs.execute('select * from people')
> > colnames = [desc[0] for desc in curs.description]
> > rowdicts = []
> > for row in curs.fetchall():
> >            rowdicts.append(dict(zip(colnames, row)))
>
> zip(colnames, row) will return:
>
> (first column name, first item of row),
> (second column name, second item of row),
> (third column name, third item of row),
> etc.
>
>
>
> --
> Steven
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Milos Zorica
+1 845 277 0549 | +1 786 471 4846

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