Project 20: Pricing Table
Python Challenge
Builds on these lessons
Step 1 of 3
Project
Measuring Memory Usage
Use tracemalloc.start(), take a snapshot before and after building a large list of pricing tiers, and compare them. tracemalloc (built into Python) shows exactly where memory was allocated — the direct way to confirm a suspected memory hog rather than guessing.
🎯 Your Task
Please add the exact code shown in the light gray box below to your editor.Do not delete your previous code, just insert these new lines in the correct place!
import tracemalloc
tracemalloc.start()
snapshot_before = tracemalloc.take_snapshot()
tiers = [{"name": f"Tier {i}", "price": i * 10} for i in range(10000)]
snapshot_after = tracemalloc.take_snapshot()
diff = snapshot_after.compare_to(snapshot_before, "lineno")
print(diff[0])