Skip to content

Instantly share code, notes, and snippets.

@ZSendokame
Last active February 16, 2024 00:06
Show Gist options
  • Save ZSendokame/9e06d568a3adf5351ed8a9e2a91dc11a to your computer and use it in GitHub Desktop.
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.
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