Short algorithm problem. Criticize my work please :)
Problem:
Given a query string: "name=larry&job=engineer"
Convert query string to a python dict object where the dict's keys are query string's fields (value before the =) and the corresponding values are query string's values (value after the '=').
Expected result: {'name': 'larry', 'job': 'engineer'}
My solution:
def to_dict(s):
r = dict()
query = s.split("&")
for item in query:
q = item.split('=')
r[q[0]] = q[1]
return r
How can I improve the solution above?
Posted Jun 16, 2017, 7:43 PM UTC
16