How can I convert
x = 'a=b&c=d'
without explicitly looking and replacing
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("&"))