Python | Collections Module | Codecademy

The collections module implements several container types in addition to the standard Python built-in collections, dict, list, set and tuple.

Below are some of the specialized data types provided by this module.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!

    • Includes 6 Courses
    • With Professional Certification

  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.

Collections Module

ChainMap
Creates a single view of multiple dictionaries or mappings in Python.

collections.Counter
A dict subclass that stores counts for hashable objects.

defaultdict
Creates a dictionary-like object that provides default values for missing keys.

deque()
Creates a deque object.

namedtuple
Creates tuple subclasses with named fields for improved code readability in Python namedtuple structures.

OrderedDict
Maintains the order in which keys were inserted in a dictionary.

UserDict
A wrapper class from collections that allows creating customized dictionary-like objects by subclassing it instead of dict.

UserList
Wrapper around list objects for easier list subclassing.

UserString
A wrapper class for string objects that makes subclassing easier.

Learn Python on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!

    • Includes 6 Courses
    • With Professional Certification

  • Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.