Created
October 20, 2017 18:45
-
-
Save chelseadole/4a00becfc8566df73ce9ab73ec68fe26 to your computer and use it in GitHub Desktop.
Code Challenge, chelsea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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