A Buffet of Specialized Data Types — Real Python

Python’s collections module provides a rich set of specialized container data types carefully designed to approach specific programming problems in a Pythonic and efficient way. The module also provides wrapper classes that make it safer to create custom classes that behave similar to the built-in types dict, list, and str.
Learning about the data types and classes in collections will allow you to grow your programming tool kit with a valuable set of reliable and efficient tools.
In this tutorial, you’ll learn how to:
Write readable and explicit code with namedtuple
Build efficient queues and stacks with deque
Count objects quickly with Counter
Handle missing dictionary keys with defaultdict
Guarantee the insertion order of keys with OrderedDict
Manage multiple dictionaries as a single unit with ChainMap
To better understand the data types and classes in collections, you should know the basics of working with Python’s built-in data types, such as lists, tuples, and dictionaries. Additionally, the last part of the article requires some basic knowledge about object-oriented programming in Python.

Getting Started With Python’s collections
Back in Python 2.4, Raymond Hettinger contributed a new module called collections to the standard library. The goal was to provide various specialized collection data types to approach specific programming problems.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What It Takes to Be a Successful Solutions Engineer at Facebook

Using Bicep for Infrastructure as Code on Azure

Simple Web Log Analyzer — Google Analytics Replacement

Tell the World About It, Even if the World Doesn’t Care

How Industries are Solving Challenges Using Ansible

Python AWS Lambda Monorepo — Part 3: Test, Build, and Deploy

Use Machine Learning and GridDB to build a Production-Ready Stock Market Anomaly Detector

Architecture Decision Studio

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Digital Marketing

Digital Marketing

More from Medium

INSERTION OF DATA AT THE BEGINNING, AFTER A NODE AND ENDING POSITION OF A LINKLIST IN PYTHON…

Hydra for managing configuration

Is Both Or Not|Codechef Solution in Python

Decorators in Python