List to dict conversion
Wujek
wujek at wujek.com
Fri Oct 3 05:17:08 EDT 2003
More information about the Python-list mailing list
Fri Oct 3 05:17:08 EDT 2003
- Previous message (by thread): List to dict conversion
- Next message (by thread): List to dict conversion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Previous message (by thread): List to dict conversion
- Next message (by thread): List to dict conversion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list