A customer's export is JSON Lines (one JSON object per line). Produce clean records and a summary:
invalid.email and a numeric amount (int or float, not bool) — otherwise
it is invalid.email stripped and lowercased; amount rounded to 2 decimals; keep only these two
fields.duplicates).Return {"records": [...], "invalid": n, "duplicates": n}.
Implement clean_jsonl. Input: text: str. Returns: dict.
import json
def clean_jsonl(text: str) -> dict:
records = [json.loads(line) for line in text.splitlines() if line.strip()]
return {"records": records, "invalid": 0, "duplicates": 0}
Run executes the public tests. Submit grades against public and hidden tests.
A customer's export is JSON Lines (one JSON object per line). Produce clean records and a summary:
invalid.email and a numeric amount (int or float, not bool) — otherwise
it is invalid.email stripped and lowercased; amount rounded to 2 decimals; keep only these two
fields.duplicates).Return {"records": [...], "invalid": n, "duplicates": n}.
Implement clean_jsonl. Input: text: str. Returns: dict.
import json
def clean_jsonl(text: str) -> dict:
records = [json.loads(line) for line in text.splitlines() if line.strip()]
return {"records": records, "invalid": 0, "duplicates": 0}
Run executes the public tests. Submit grades against public and hidden tests.