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'}
Rick Donato

Want to become a programming expert?

Here is our hand-picked selection of the best courses you can find online:
Python Zero to Hero course
Python Pro Bootcamp
Bash Scripting and Shell Programming course
Automate with Shell Scripting course
The Complete Web Development Bootcamp course
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial