Exercise · beginner · 15 min
Keep identifiers as text and parse yes/no flags
Member IDs and postcodes have leading zeros that must survive, and the opt-in flag arrives as Y, yes, TRUE or 1. Parse the flag to a real boolean without guessing.
The rules
These rules decide what a correct result is. Your answer is checked on this dataset and on hidden datasets that follow the same rules.
Input
members(member_id, postcode, opted_in) — text. member_id is unique and always present.
Rules
member_id and postcode are identifiers: keep them as text exactly as given, except that postcode has
ASCII whitespace removed at both ends. Never convert them to numbers (00123 must stay 00123).
opted_in: remove ASCII whitespace at both ends, then lowercase, then:
y, yes, true, 1 → true
n, no, false, 0 → false
Quarantine with reason bad_flag when opted_in is missing or anything else (a missing answer is not "no").
Outputs (row order does not matter)
clean(member_id text, postcode text, opted_in bool)
exceptions(member_id text, reason text)The data
members · 17 rows, first 12 shown
| member_id | postcode | opted_in |
|---|---|---|
| 008417 | 98506· | true |
| 000002 | ·02139· | maybe |
| 002939 | missing | 0 |
| 015246 | ·51389 | y |
| 077927 | ·08222 | N |
| 092803 | 30041 | true |
| 085051 | ·12134· | N |
| 000001 | 00501 | yes |
| 004197 | ·52402 | true |
| 016386 | ·46532· | no |
| 016648 | ·20460 | yes |
| 078978 | missing | no |
What you practise
- identifiers
- booleans
- mappings
- type conversion
Your answer is also checked on hidden datasets generated from the same rules.
Sign in to bookmark this and keep private notes.