Last active
February 16, 2024 00:06
-
-
Save ZSendokame/9e06d568a3adf5351ed8a9e2a91dc11a to your computer and use it in GitHub Desktop.
Parsing and unparsing of Query Strings. Saving first ones instead of last ones.
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_qs(qs: str) -> dict: | |
kvs = qs.split('&') | |
parsed = {} | |
for kv in kvs: | |
key, value = kv.split('=') | |
if key not in parsed: | |
parsed[key] = value | |
return parsed | |
def unparse_qs(parsed: dict) -> str: | |
result = [f'{key}={value}' for key, value in parsed.items()] | |
return '?' + '&'.join(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment