Python - Split a String into a Dictionary

To split a string into key value pairs (i.e dict) the following can be used,

>>> string = "abc=123,xyz=456"
>>> dict(x.split('=') for x in string.split(','))
{'xyz': '456', 'abc': '123'}

About the Author


R Donato

Rick Donato is the Founder and Chief Editor of He currently works as an SDN/NFV Solutions Architect and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001