List to dict conversion

Wujek wujek at wujek.com
Fri Oct 3 05:17:08 EDT 2003


Hi!

 From list:
 >>> l
['key1:val1', 'key2:val2']

I want dict:
 >>> d
{'key2': 'val2', 'key1': 'val1'}

Is there any better (faster, simplier, prettier?) solution than this?
 >>> for line in l:
...   spl=line.split(':')
...   d[spl[0]] = spl[1]


Regards.





More information about the Python-list mailing list