May 2021
Intermediate to advanced
142 pages
3h 37m
English
The collections standard library module is a standby for many Python developers. It provides a number of utilities (particularly defaultdict, Counter, and namedtuple) that help reduce boilerplate code and make it possible to write concise Python. After you read through this section on collections, you will be familiar with some of the utilities in the module and be prepared to include them in your projects.
defaultdict is a convenience provided by the collections module. defaultdict allows you to add values to dictionaries concisely and reduce boilerplate code.
Consider, for example, if you had a program that used a dict to map file owners to files. The following ...