Step: Nested data: sum over a list of dicts
Nested data: sum over a list of dicts
sum(expr for item in iterable) combines a generator expression (like a list comprehension, but without the [...]) with the built-in sum() to total up a computed value across items.
Why it matters: aggregating over a list of dicts (rows of data) is one of the most common real-world Python tasks.
Example: sum(x * 2 for x in [1, 2, 3]) is 12.
Your turn: compute the total inventory value (qty * price for each item, summed) for inventory.
Pitfall: mixing an int qty with a float price promotes the whole sum to float — that's why the answer is 31.0, not 31.
Setup:
Your code:Expected output:
Step 16 of 18