runtime
452 / 500
question 452 Reliable Data Pipelines · easy

Fix the reject report

The ingest step reports which lines of an event file were rejected. Support has two complaints: every reported line number is one lower than the line they find in their editor, and the blank line at the end of every file is reported as broken. Fix read_events so the report is right; the events it returns are already correct.

Functionread_events(lines)
Returns(events, rejected): JSON objects in order, and the line numbers (counting from 1) of non-blank lines that aren't JSON objects
Blanka line that is empty or only spaces is neither an event nor rejected
Examples
callread_events(['{"id": "48000000581", "type": "PushEvent"}', '{"id": "4800', '{"id": "48000007504", "type": "WatchEvent"}', ''])returns([{'id': '48000000581', 'type': 'PushEvent'}, {'id': '48000007504', 'type': 'WatchEvent'}], [2])
callread_events(['{"id": "1"}', '[1, 2]'])returns([{'id': '1'}], [2])
callread_events(['bad', '{"id": "2"}'])returns([{'id': '2'}], [1])

Loading your progress…

Fix the reject report — Python practice · Runtime