Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'column': 0.07; '(first': 0.09; '[1,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "'b',": 0.16; "('b',": 0.16; "('c',": 0.16; '(second': 0.16; '1),': 0.16; '2),': 0.16; '3)]': 0.16; '7:58': 0.16; "[('a',": 0.16; 'code?': 0.16; 'iterator': 0.16; 'row)': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'wrote:': 0.18; 'advance.': 0.19; 'cc:addr:python.org': 0.22; 'fine': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'list:': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; "d'aprano": 0.31; 'piece': 0.31; 'produces': 0.31; 'steven': 0.31; 'url:python': 0.33; 'third': 0.33; 'except': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'nov': 0.38; 'url:library': 0.38; 'list,': 0.38; 'rather': 0.38; 'does': 0.39; 'bad': 0.39; 'url:mail': 0.40; 'read': 0.60; 'url:3': 0.61; 'first': 0.61; 'email addr:gmail.com': 0.63; 'zip': 0.64; 'skip:r 30': 0.69; 'special': 0.74; 'demand': 0.91; 'same,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=lVa0GT1ndho3EmNUcQCu8XxjNY0xNEjr2psC68BYLBI=; b=rY0+7wUX8Mnad36nh4jc3/5wtR9gbofc5UMzxPwmhBfKx0s4Z4RvM0Y+Fxx5f+DouT UBJ2R2yK05v1mUs46FtwnNrXu+ES4tyPWOi7eP8/6STwDT2+Nk9WYjqxp7SVK/kRGtQM 0NGN//MTRXqG/rlyfLGbNMytC2Bh570gw3P+V+HL9iPqSoaoWuLbyKmLsUoYH+Frds44 ccgMt6mNGEnFMWqk+sk5AaXoCll6hG/aajCgWqMtx+2Q1vRqwgwbD5dcA4D3sTErhtzs AjlPNNmaUO8fl6cBm+ZDjLTx2/wDlmc/0H1AwKykpocna5L3Ms4Cxb9uJBIqTgPXXTZR +jYw== MIME-Version: 1.0 X-Received: by 10.112.36.197 with SMTP id s5mr23235191lbj.30.1415531185766; Sun, 09 Nov 2014 03:06:25 -0800 (PST) In-Reply-To: <545f48b9$0$13005$c3e8da3$5496439d@news.astraweb.com> References: <545f48b9$0$13005$c3e8da3$5496439d@news.astraweb.com> Date: Sun, 9 Nov 2014 08:06:25 -0300 Subject: Re: What does zip mean? From: milos zorica To: "Steven D'Aprano" Content-Type: multipart/alternative; boundary=001a113433687f06b305076b09c9 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 120 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415531192 news.xs4all.nl 2878 [2001:888:2000:d::a6]:37520 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 7265 X-Received-Body-CRC: 2522778470 Xref: csiph.com comp.lang.python:80420 --001a113433687f06b305076b09c9 Content-Type: text/plain; charset=ISO-8859-1 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 --001a113433687f06b305076b09c9 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
sorry my bad

On Sun, Nov 9, 2014 at 7:58 AM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:<= br>
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])

=3D> [('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 =3D [desc[0] for desc in curs.description]
> rowdicts =3D []
> for row in curs.fetchall():
>=A0 =A0 =A0 =A0 =A0 =A0 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 4= 71 4846
--001a113433687f06b305076b09c9--