Posts Tagged ‘Empty’

How to delete items from a dictionary in Python?

You can use the del statement to delete individual items from a dictionary, or the clear() method to delete all items. # Create an empty dictionary d = {}   # Add an item d["name"] = "Fido" assert d.has_key("name")   # Delete the item del d["name"] assert not d.has_key("name")   # Add a couple of [...]