Group transactions
Your task
You are given a list of transaction records, each a dict with keys 'user', 'amount' (int cents), and 'currency' (string). Group the transactions by (user, currency) and return a list of dicts with keys 'user', 'currency', 'total' (sum of amounts), and 'count' (number of transactions). Sort the output by 'user' ascending, then 'currency' ascending. Amounts may be negative (refunds). The input list may be empty.
Examples
aggregate_transactions(records: list[dict]) -> list[dict]Example 1
Input
aggregate_transactions([{"user": "a", "amount": 100, "currency": "USD"}, {"user": "a", "amount": 50, "currency": "USD"}, {"user": "b", "amount": 200, "currency": "EUR"}])Output
| user | currency | total | count |
|---|---|---|---|
| a | USD | 150 | 2 |
| b | EUR | 200 | 1 |