Generate a code snippet in Python to convert a string with the following format to a dictionary. (name1=123&name2=456&name3=789).
name1=123&name2=456&name3=789
inp = "name1=123&name2=456&name3=789"
kv = inp.split("&")
d = {}
for i in kv:
    k,v = i.split("=")
    d[k] = v

print(d)