Select as dictionary...

Duncan Booth duncan.booth at invalid.invalid
Mon Oct 1 10:08:19 EDT 2007


"J. Clifford Dyer" <jcd at sdf.lonestar.org> wrote:

> aia.execute("SELECT id, w from list")
> links=aia.fetchall()
> linkdict = dict()
> for k,v in links:
>     linkdict[k] = v
> print linkdict

Wouldn't it be simpler just to do:

  aia.execute("SELECT id, w from list")
  linkdict=dict(aia.fetchall())

even better would be to use an iterator to avoid fetching the entire 
resultset as a list.



More information about the Python-list mailing list