Removing from dictionaries – the pop() method and the del statement
A common use case for a dictionary is as an associative store: we can keep an association between key and value objects. This means that we may be doing any of the CRUD operations on an item in the dictionary.
Create a new key and value pair
Retrieve the value associated with a key
Update the value associated with a key
Delete the key (and value) from the dictionary
We have two common variations on this theme:
We have the in-memory dictionary,
dict
, and the variations on this theme in thecollections
module. The collection only exists while our program is running.We also have persistent storage in the
shelve
anddbm
modules. The data collection is a persistent file in the file system.
These are very similar, the distinctions between a shelf.Shelf
and dict
object are minor. This allows us to experiment with a dict
and switch to a Shelf
without making dramatic changes to a program.
A server process will often have multiple, concurrent...