Workspace/Coding labs
Loading progress

Validate and normalize a batch request

Foundation50 min

Implement normalize_batch(payload), returning canonical request records while enforcing shape, exact types, bounds, and unique IDs.

Your task

  1. Accept a list of zero to 100 dictionaries, each with exactly id and limit keys.
  2. Require a nonempty string id after stripping whitespace and an exact integer limit from 1 through 20; reject booleans.
  3. Strip IDs without changing case and reject IDs that become duplicates after stripping.
  4. Return new dictionaries in input order. Raise ValueError for every invalid input and do not mutate the input.

Examples

EXAMPLE 1

Input[{"id":" A ","limit":2}]

Output[{"id":"A","limit":2}]

Only surrounding whitespace is normalized.
EXAMPLE 2

Input[{"id":"A","limit":true}]

OutputValueError

Boolean values are explicitly excluded.
solution.pyPython 3.12