PY-48
Parse Rows and Keep Source IDs
Task
Write parse_rows(text, delimiter). Each physical line should contain exactly
three fields:
record_id<delimiter>label<delimiter>numeric_value
Split the input with text.splitlines(). Line numbers begin at 1. Preserve the
unmodified split fields in a list called raw_fields, but strip surrounding
whitespace from record_id, label, and the text passed to float.
Return (accepted, rejected). An accepted record has exactly these keys:
Reject under this exact first-failure order:
- field count is not three:
"expected 3 fields"; - stripped record ID is empty:
"empty record id"; - numeric conversion raises
ValueError:"invalid numeric value".
A rejected record contains source_line, raw_fields, and reason. Continue
after rejected rows and preserve source order within both result lists.
Example
The source line and raw fields remain available after conversion, so later reports can point back to the input evidence.
Your implementation
Edit solution.py and keep this function signature:
delimiter is a non-empty string. Return new lists and dictionaries. Do not
print or ask for input.