Union Operators to Dict

How can I convert

x = 'a=b&c=d'


{'a':'b', 'c':'d'}

without explicitly looking and replacing & and = to , and : respectively?


You have a DSL (domain specific language) for defining a dict. You have to parse the string, then evaluate the result. Luckily, that’s as simple as

d = dict(kv.split("=", 1) for kv in x.split("&"))