Skip to content

Instantly share code, notes, and snippets.

@chelseadole
Created October 20, 2017 18:45
Show Gist options
  • Save chelseadole/4a00becfc8566df73ce9ab73ec68fe26 to your computer and use it in GitHub Desktop.
Save chelseadole/4a00becfc8566df73ce9ab73ec68fe26 to your computer and use it in GitHub Desktop.
Code Challenge, chelsea
def parse_query(query):
query_dictionary = {}
split_query = query[1:].split('&')
for item in split_query:
item_key, item_val = item.split('=')[0], item.split('=')[1]
if item_key not in query_dictionary:
query_dictionary[item_key] = item_val
elif item_key in query_dictionary:
prev_contents = query_dictionary[item_key]
query_dictionary[item_key] = [prev_contents]
query_dictionary[item_key].append(item_val)
return query_dictionary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment