请告诉我将列表对象转换为字典的最简单方法。所有参数如下所示:
['a=1', 'b=2', ...]
我想把它转换成:
{'a': '1', 'b': '2' ...}
你可以使用:
>>> x
['a=1', 'b=2']
>>>
>>> dict( i.split('=') for i in x )
{'a': '1', 'b': '2'}
>>>
For each element in the list, split
on the equal character, and add to dictionary using the resulting list from split
.