Unit: Unit 4: Strings, Lists, and Tuples • Interactive Practice
Interactive Python programming tutorial and practice in your browser.
# Remove items from the list by matching value
inventory = ["docking station", "laptop", "mousepad", "wireless mouse", "mechanical keyboard"]
# 1. Remove "mousepad" from the list
inventory.remove("mousepad")
# 2. Check membership before removal to avoid errors
target = "docking station"
if target in inventory:
inventory.remove(target)
print("Inventory after remove operations:", inventory)