Tracing updates, get, and pop on a dictionary

A school supply room tracks stock with the Python code below. Trace the code, then fill in the table with the final result of each expression. Enter integers for numbers and True or False for the membership test.


Python
stock = {"pens": 12, "pads": 5, "tape": 7}
stock["pens"] -= 4
stock["clips"] = 30
stock["pads"] = stock.get("pads", 0) + stock.get("glue", 3)
removed = stock.pop("tape")
stock["clips"] += removed
ExpressionFinal result
value stored under key pens
value stored under key pads
value stored under key clips
len(stock)
"tape" in stock

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Dictionaries Questions: