← All notes

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

Sources

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

Permanent ID: iil:note:pn4dv2dt

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.},
}

Markdown

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.

All artifact files (JSON index)

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.