Easy way to convert list to dict

Please tell me the easiest way to convert a list object to a dictionary. All parameters are as follows:

['a=1', 'b=2', ...] 

And I want to convert it to:

 {'a': '1', 'b': '2' ...} 
+4
source share
2 answers

You can use:

 >>> x ['a=1', 'b=2'] >>> >>> dict( i.split('=') for i in x ) {'a': '1', 'b': '2'} >>> 
+13
source

For each element of the split list on an equal symbol and add to the dictionary using the resulting list from split .

+5
source

Source: https://habr.com/ru/post/1500101/


All Articles