1. Take a snapshot
Write code Easy ✓ CompletedWrite snapshot(items) that returns a new list or dict with the same contents as items, so that later changes to the original do not show up in the snapshot. It must work for both lists and dicts.
def snapshot(items):
# return an independent copy of the list or dict
pass
cart = ["milk", "eggs"]
saved = snapshot(cart)
cart.append("bread")
print(saved)
def snapshot(items):
return items.copy()
cart = ["milk", "eggs"]
saved = snapshot(cart)
cart.append("bread")
print(saved)