1. Predict the category totals
Predict the output Easy ✓ CompletedRead the code and type exactly what it prints.
expenses = [
{"category": "food", "amount": 4.5},
{"category": "books", "amount": 12.0},
{"category": "food", "amount": 3.0},
]
totals = {}
for e in expenses:
totals[e["category"]] = totals.get(e["category"], 0) + e["amount"]
print(totals)
print(len(expenses), "expenses")
print(f"food: {totals['food']:.2f}"){'food': 7.5, 'books': 12.0}
3 expenses
food: 7.50