Group by with aggregate
Your task
Implement GROUP BY with an aggregate. Given rows (list of dicts), a group_col name, an agg_col name, and an agg function one of 'sum','count','avg', group rows by row[group_col] and compute the aggregate of row[agg_col] within each group. 'count' ignores agg_col and counts rows; 'avg' is the floating-point mean. Return a list of [group_value, aggregate] pairs sorted ascending by group_value. avg values must equal the exact float mean.
Examples
group_aggregate(rows: list[dict], group_col: str, agg_col: str, agg: str) -> list[list]Example 1
Input
group_aggregate([{"dept": "eng", "sal": 100}, {"dept": "eng", "sal": 200}, {"dept": "hr", "sal": 50}], "dept", "sal", "sum")Output
[["eng", 300], ["hr", 50]]