Validate and normalize a batch request
Implement normalize_batch(payload), returning canonical request records while enforcing shape, exact types, bounds, and unique IDs.
Your task
- Accept a list of zero to 100 dictionaries, each with exactly id and limit keys.
- Require a nonempty string id after stripping whitespace and an exact integer limit from 1 through 20; reject booleans.
- Strip IDs without changing case and reject IDs that become duplicates after stripping.
- 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}]
EXAMPLE 2
Input[{"id":"A","limit":true}]
OutputValueError
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor