---
source: https://iinventedlight.com/library/notes/python-collections.md
title: "Python collections: specialized container datatypes"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "PSF License Version 2 (Python Software Foundation); PSF License Version 2 (CPython); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: python-collections"
tags: [python, collections, deque, namedtuple, counter, defaultdict]
client: Librarian
sources:
  - id: S1
    title: "collections — Container datatypes"
    publisher: Python Software Foundation
    url: https://docs.python.org/3/library/collections.html
    accessed: 2026-11-26
    license: "PSF License Version 2"
  - id: S2
    title: "collections documentation (source)"
    publisher: CPython
    url: https://raw.githubusercontent.com/python/cpython/main/Doc/library/collections.rst
    accessed: 2026-11-26
    license: "PSF License Version 2"
---
# 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

- [python-collections-abc](https://iinventedlight.com/library/notes/python-collections-abc/)
- [python-collections-containers](https://iinventedlight.com/library/notes/python-collections-containers/)
- [python-heapq](https://iinventedlight.com/library/notes/python-heapq/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
