Real Python
Real Python

@realpython

4 Tweets 7 reads Aug 07, 2022
🐍⚙️ Python Tricks — Custom Python dictionaries
Creating dictionary-like classes may be a requirement in your Python career.
You can get a custom Dictionary by subclassing the UserDict from collections.
But there are other ways to get this 👇
Inheriting From Python's Built-in dict Class
Compared with the UserDict, subclassing the built-in dict class can be tricky, labor-intensive, and error-prone.
You could need your own version of other methods depending on your requirements.
Creating dictionary-like class from an abstract base class, like MutableMapping.
This class provides concrete generic implementations of most of the dictionary methods.
This process will require a fair amount of work and advanced knowledge of Python and its data model.
Learn more about creating your custom Dictionary-like class implementations and real-life practical examples by following this link realpython.com.

Loading suggestions...