Using the standard library extensions
We'll look at some extensions to built-in classes that are already part of the standard library. These are the collections that extend or modify the built-in collections. Most of these are covered in one form or another in books such as Python 3 Object Oriented Programming.
We'll look at the following six library collections:
The
namedtuple()
function creates subclasses of tuple subclasses with named attributes. We can use this instead of defining a complete class, which merely assigns names to the attribute values.deque
(note the atypical spelling) is a double-ended queue, a list-like collection that can perform fast appends and pops on either end. A subset of the features of this class will create single-ended stacks or queues.In some cases, we can use
ChainMap
instead of merging mappings together. This is a view of multiple mappings.An
OrderedDict
collection is a mapping in which the original key entry order is maintained.defaultdict
(note the atypical...