In addition to Python’s built-in data structures (such as tuples, dicts, and lists), a library module called collections provides data structures with additional features, some of which are specializations of the built-in ones.
Import the module:
import collectionsSpecialized container datatypes are usually dict subclasses or wrappers around other classes like lists, tuples, etc.
Notable implementations are :
- the
Counterclass used for counting hashable objects. defaultdictclass used as a faster implementation of a specialised dictionary.namedtupleclass used for defining a meaning for every position in a tuple, often useful with databases or CSV files.