When Python general purpose built-in containers (tuple
, list
, set
, and dict
) aren't enough, we can find specialized container datatypes in the collections
module. They are:
Data type | Description |
| Factory function for creating tuple subclasses with named fields |
| List-like container with fast appends and pops on either end |
| Dictionary-like class for creating a single view of multiple mappings |
| Dictionary subclass for counting hashable objects |
| Dictionary subclass that remembers the order entries were added |
| Dictionary subclass that calls a factory function to supply missing values |
| Wrapper around dictionary objects for easier dictionary subclassing |
| Wrapper around list objects for easier list subclassing |
| Wrapper around string objects for easier string subclassing |
We don't have the room to cover all of them, but you can find plenty of examples in the official documentation, so here I'll just give a small example...