Sum sales by category

Write codeEasy10 min

Your task

A shop's daily sales feed stores one line item per row as "category,amount", where amount is an integer that may be negative (a refund). Build the mini pivot the manager sees each evening: a dictionary mapping each category to the sum of its amounts. Example: ["toys,20", "games,15", "toys,5"] gives {"toys": 25, "games": 15}.

Examples

category_totals(rows: list[str]) -> dict[str,int]
Example 1
Inputcategory_totals(["toys,20", "games,15", "toys,5"])
Output{"toys": 25, "games": 15}