Select as dictionary...

Diez B. Roggisch deets at nospam.web.de
Mon Oct 1 13:18:32 EDT 2007


Abandoned wrote:

> Also if i need a list id what can i do ?
> 
> aia.execute("SELECT id, w from list")
> links=aia.fetchall()
> 
> I want to..
> 
> idlist=[1, 2, 3] ( I don't want to use FOR and APPEND because the
> query have 2 million result and i want to speed)

It will always return a list of tuples, so even if you'd do


select  id from list


you'd end up with

[(1,), ...]

But you shouldn't bother - a simple

idlist = [v[0] for v in links]

should do it. Because this program shows that it takes only a split-second
to process 2 million list-entries and create a new one:

import time

two_million = range(2000000)

start = time.time()
[i * 2 for i in two_million]

used = time.time() - start

print used


Need 0.8 seconds on my machine. So - don't bother.

Diez



More information about the Python-list mailing list