collection

In Python, a collection is any container data structure that stores and organizes multiple items, including built-ins like lists, dictionaries, lists, and tuples, as well as specialized data types from the collections module in the standard library.

A collection can hold multiple objects in memory and provides functionality to insert, remove, and iterate over them. The collections module in Python’s standard library offers specialized containers, such as:

  • Counter for counting hashable objects
  • deque for fast appends and pops from both ends
  • namedtuple for creating lightweight object-like tuples

These data structures address specific use cases and often offer performance advantages over regular container types.

Tutorial

Python's collections: A Buffet of Specialized Data Types

In this tutorial, you'll learn all about the series of specialized container data types in the collections module from the Python standard library.

intermediate data-structures python

For additional information on related topics, take a look at the following resources:


By Dan Bader • Updated Jan. 24, 2025