Converting a list to a dictionary
Samuel
knipknap at gmail.com
Wed Mar 14 16:22:10 EDT 2007
On Mar 14, 9:52 pm, Bruno Desthuilliers
<bdesth.quelquech... at free.quelquepart.fr> wrote:
> res_dict = dict((r.get_id(), r) for r in res_list)
>
> or if you have to be compatible with older python versions:
>
> res_dict = dict([(r.get_id(), r) for r in res_list])
Yep, that works. Strange, I was sure I had tested the latter, but I
must have been doing something wrong.
Thanks for your help!
-Samuel
More information about the Python-list
mailing list