Pivot table aggregation
Your task
You are given rows, a list of dicts each with keys 'region', 'product', and 'amount' (an integer). Build a pivot table: return a list of [region, product, total] triples giving the summed 'amount' for every (region, product) pair that appears. Sort the output ascending by region, then by product. Regions/products are non-empty strings; amounts may be negative.
Examples
pivot_totals(rows: list[dict]) -> list[list]Example 1
Input
pivot_totals([{"region": "us", "product": "a", "amount": 10}, {"region": "us", "product": "a", "amount": 5}, {"region": "eu", "product": "b", "amount": 3}])Output
[["eu", "b", 3], ["us", "a", 15]]