Vor Vor - 9 months ago 42
Python Question

How to split a string within a list to create key-value pairs in Python

I have a list that looks like this:

[ 'abc=lalalla', 'appa=kdkdkdkd', 'kkakaka=oeoeoeo']

And I want to split this list by '=' so that everything on the left side will become keys and on the right, values.


a = [ 'abc=lalalla', 'appa=kdkdkdkd', 'kkakaka=oeoeoeo']
d = dict(s.split('=') for s in a)
print d

{'kkakaka': 'oeoeoeo', 'abc': 'lalalla', 'appa': 'kdkdkdkd'}