PY-71
Summarize Named Evaluation Groups
Task
Write summarize_evaluation_groups(expected, produced, row_groups, group_order).
The three row sequences are aligned: item i in each sequence describes one
comparison. expected[i] and produced[i] may be strings or numbers, and they
match when Python equality says they match. row_groups[i] names the group for
that row. group_order is a non-empty sequence of unique group names and
defines the order of the output, including groups with no rows. Every row
group must occur in group_order.
Return a dictionary with groups, total, correct, accuracy, and
error_rate. groups is a list of records in exactly group_order; each
record has:
group, count, correct, accuracy, error_rate
For a group, count is its number of rows and correct is the number for
which expected equals produced. For a non-empty group:
accuracy = correct / count
error_rate = (count - correct) / count
For an empty group, both fractions are exactly 0.0. The top-level values use
the same rules over all rows; for an input with no rows, total and correct
are 0 and both top-level fractions are 0.0.
If the row sequences have different lengths, group_order is empty or has a
duplicate, or a row names an unknown group, raise ValueError with
"invalid evaluation groups". A rejected input must not be partly returned.
Example
The records are short: (count=3, correct=2), long: (1, 0), and
empty: (0, 0). Their accuracies are 2/3, 0.0, and 0.0; the top-level
accuracy is 2/4.
Your implementation
Edit solution.py and keep this function signature:
Return ordinary Python numbers in the records. Preserve every input sequence and its row order. Do not print or ask for input.