June 2019
Beginner to intermediate
770 pages
19h 24m
English
The collections module defines a number of collections above and beyond the built-in container classes. The container classes include namedtuple(), deque, ChainMap, Counter, OrderedDict, and defaultdict. All of these are examples of classes based on ABC definitions.
The following is a quick interaction to show how we can inspect collections to see the methods that they support:
>>> isinstance({}, collections.abc.Mapping)
True
>>> isinstance(collections.defaultdict(int), collections.abc.Mapping)
True
We can inspect the simple dict class to see that it follows the Mapping protocol and will support the required methods.
We can inspect a defaultdict collection to confirm that it is also part of the Mapping class hierarchy. ...
Read now
Unlock full access