Today’s challenge
Build the solution
Write a function called clean_temperatures(values) that validates a mixed sensor feed.
Return contract: A dictionary with readings (a list of integers) and rejected (a list of zero-based indexes).
Input bounds: 0–200 JSON values; each string is at most 80 characters. Only ASCII 0–9 count as digits.
Keep the supplied driver below your implementation. It reads one JSON object and prints your return value as JSON. The driver may also probe the behaviour described above; those probe fields are part of the test input.
- Accept integer values and strings containing an ASCII integer, with optional leading + or - and optional surrounding whitespace.
- Accept only temperatures from -40 through 85 inclusive. Reject booleans, floats, empty strings, a sign without digits, and other values.
- Preserve the order of accepted readings. Report the zero-based positions of rejected values.
The Twist: In Python, True behaves like the integer 1 in many expressions. It is still a faulty reading for this contract.
Sample
Input
{"values":[25," -40 ","85",true,25.0,"86","bad"]}Expected output
{"readings":[25,-40,85],"rejected":[3,4,5,6]}