sorry my bad On Sun, Nov 9, 2014 at 7:58 AM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote:
> satishmlm...@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
-- https://mail.python.org/mailman/listinfo/python-list