Group transactions

Write codeMedium25 minStripe and PayPal style

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
Inputaggregate_transactions([{"user": "a", "amount": 100, "currency": "USD"}, {"user": "a", "amount": 50, "currency": "USD"}, {"user": "b", "amount": 200, "currency": "EUR"}])
Output
usercurrencytotalcount
aUSD1502
bEUR2001