Search RU
Tasks / Logs / Traceback by request id
Statement medium

Traceback by request id

`group_tracebacks(lines)` parses a log where one request may leave a multi-line
traceback, and groups the blocks by `request id`.

A header line starts with an ISO timestamp and contains `request=<id>`:

```
2026-05-01T10:00:00Z request=req-1 ERROR checkout failed
Traceback (most recent call last):
File "orders.py", line 42, in handle
total = price / count
ZeroDivisionError: division by zero
```

Rules:

- a new record starts only on a header line;
- every line after a header, up to the next header, belongs to that record;
- a traceback starts at `Traceback (most recent call last):` and includes all
following lines of the record, including the source line and the final
exception line;
- leading spaces inside a block are preserved;
- one block is one result string: its lines are joined with `\n` and there is no
trailing newline;
- the result is `{request_id: [block, ...]}`; if one `request id` has several
tracebacks, the blocks follow the order of appearance;
- records without a traceback do not appear in the result;
- an empty input gives `{}`.

Write tests for: one complete traceback, two blocks with the same `request id`,
different `request id`s, a record without a traceback, and an empty log.

logstracebackparsinggrouping
test_solution.py Python 3.14
AI mentor

The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.

Log in and ask
Hints 1 of 3 unlocked · attempts: 0
Hint 1

Where does one log record end and the next begin? Which traceback lines are not
headers but still have to end up in the block?

Hint 2 — unlocks after 1 attempt
Hint 3 — unlocks after 3 attempts