Converting a list to a dictionary

Samuel knipknap at gmail.com
Wed Mar 14 21:07:58 CET 2007


Hi,

is there a short version for this?

res_dict = {}
for resource in res_list:
  res_dict[resource.get_id()] = resource

This does not work:

res_dict = dict([r.get_id(), r for r in res_list])

-Samuel




More information about the Python-list mailing list