Python collections: specialized container datatypes
Answer: The collections module implements specialized container datatypes as alternatives to dict, list, set, and tuple.
The specialized containers
namedtuple is a factory function for creating tuple subclasses with named fields.
deque is a list-like container with fast appends and pops on either end.
ChainMap builds a single view of multiple mappings.
Counter counts hashable objects.
Dict subclasses and wrappers
OrderedDict is a dict subclass that remembers the order entries were added.
defaultdict calls a factory function to supply missing values.
UserDict, UserList, and UserString wrap built-in objects to make subclassing easier.
ChainMap can also group mappings so they are treated as a single unit.
See also
Claims
- id: C1 claim: The module implements specialized container datatypes as alternatives to the built-in containers. source: S1 evidence: "implements specialized container datatypes providing alternatives to"
- id: C2 claim: namedtuple is a factory function for creating tuple subclasses with named fields. source: S1 evidence: "factory function for creating tuple subclasses with named fields"
- id: C3 claim: deque is a list-like container with fast appends and pops on either end. source: S2 evidence: "list-like container with fast appends and pops on either end"
- id: C4 claim: OrderedDict remembers the order entries were added. source: S2 evidence: "dict subclass that remembers the order entries were added"
Sources
- [S1] collections — Container datatypes. Python Software Foundation. https://docs.python.org/3/library/collections.html . License: PSF License Version 2. Accessed 2026-11-26.
- [S2] collections documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/collections.rst . License: PSF License Version 2. Accessed 2026-11-26.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, collections — Container datatypes; CPython, collections documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, collections — Container datatypes; CPython, collections documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python collections: specialized container datatypes." iinventedlight Library, iil:note:pn4dv2dt, version of 2026-11-26. https://iinventedlight.com/library/notes/python-collections/. License: CC-BY-4.0.
@misc{iil_note_pn4dv2dt,
author = {{iinventedlight}},
title = {{Python collections: specialized container datatypes}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/python-collections/},
note = {Permanent ID iil:note:pn4dv2dt. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- python-collections.schema.json (schema; CC-BY-4.0)
- python-collections.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-collections.md.