Exercise 8: Running Totals from a List of Tuples — Possible Solution ==================================================================== transactions = [ ("food", 12.50), ("transport", 3.20), ("food", 8.00), ("entertainment", 15.00), ("transport", 2.80), ] totals = {} index = 0 while index < len(transactions): category, amount = transactions[index] if category in totals: totals[category] += amount else: totals[category] = amount index += 1 print(totals) Output: {'food': 20.5, 'transport': 6.0, 'entertainment': 15.0} WHY THIS WORKS AS AN ANSWER ------------------------------ transactions[index] retrieves one (category, amount) tuple at a time, and category, amount = transactions[index] unpacks it into two named variables in one line — the same unpacking technique from the tuples lesson, just applied inside a while loop instead of a for loop. The accumulation logic is identical to Exercise 3's counting pattern (check whether the key exists yet, then either start it or add to it) — the only difference is adding a variable amount instead of always adding a fixed 1. Recognising that these are "the same pattern" is the real skill here: a huge number of real-world aggregation problems are just this one idea (initialise-or-accumulate keyed by some category) applied to whatever data you're actually working with.