Dictionary of tuples from query question
Ben Sizer
kylotan at gmail.com
Mon Nov 14 09:20:21 EST 2005
David Pratt wrote:
> With the tip, I
> simplified my code to:
>
> vlist_dict = {}
> record_count = 0
> for record in cursor.fetchall():
> record_count += 1
> vlist_dict[record_count] = tuple(record)
> print vlist_dict
I missed your original post, so forgive me if I'm missing the point
here. But if you're indexing the dictionary with integers, I expect you
could just use a list instead, which I think could make your code look
like this:
vlist = [tuple(record) for record in cursor.fetchall() ]
print vlist
In Python there is rarely any need to manually increment index values
within a loop. If you do need the record count here, len(vlist) would
be equivalent.
--
Ben Sizer
More information about the Python-list
mailing list