Log inBook a Demo
BuildMidFrontendAuto-graded

Parse and rebuild URL query strings by hand

Rewrite parse() and stringify() without urllib, handling special characters, repeated keys and empty values.querystring.py has a parse(qs) that turns a query string into a dict and a stringify(obj) that turns it back. Neither meets the contract in the file's docstring yet. Rewrite parse so it handles percent-encoding, + as a space, repeated keys and empty values. Rewrite stringify so it sorts keys and encodes its output, which must parse back to the same dict. Do the splitting and the %XX coding yourself, without parse_qs, urlencode, quote or unquote.
35 min
python

You're done when

  • Ordinary query strings parse into the expected dict, with each pair split on its first =.
  • %XX sequences and + decode correctly, in keys as well as values.
  • A key that appears more than once becomes a list in first-seen order; a key seen once stays a string.
  • a= and a bare b both parse to an empty string.
  • parse agrees with a standard reference parser on common inputs.
  • stringify sorts keys, percent-encodes special characters (a space becomes %20) and expands lists back into repeated keys in list order.
  • Running stringify then parse gives back the same dict, and stringify output is stable.
  • None of the urllib.parse query-string or quoting helpers are used.

What it measures

Back-end developmentWhether each encoding rule is applied in the right place, on keys as well as values.
PythonDecoding `%XX` to bytes before UTF-8, so characters like `é` come through intact.
Round-tripWhether the two functions undo each other, including on repeated keys and empty values.

Your environment

Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish

Start this lab

35 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo