On Oct 29, 9:35 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> I'm trying to find the fastest way to convert an sql result into a
> dict or list.
>>> from collections import defaultdict
>>> results = defaultdict(defaultdict)
>>> for contact_id, field_id, field_name, value in sql_result:
... results[contact_id][field_id] = value
... results[contact_id][field_name] = value
...
This lets you reference things in a straightforward way:
>>> results[1]['email']
'[EMAIL PROTECTED]'
If you'd prefer to use only the ids for reference:
>>> results = defaultdict(defaultdict)
>>> for contact_id, field_id, field_name, value in sql_result:
... results[contact_id][field_id] = (field_name, value)
...
>>> results[1][1]
('address', 'something street')
Hope this helps.
--
http://mail.python.org/mailman/listinfo/python-list