Real Python: Using OrderedDict in Python :
by:
blow post content copied from Planet Python
click here to view original post
Sometimes you need a Python dictionary that remembers the order of its items. In the past, you had only one tool for solving this specific problem: Python’s OrderedDict
. It’s a dictionary subclass specially designed to remember the order of items, which is defined by the insertion order of keys.
This changed in Python 3.6. The built-in dict
class now keeps its items ordered as well. Because of that, many in the Python community now wonder if OrderedDict
is still useful. A closer look at OrderedDict
will uncover that this class still provides valuable features.
In this video course, you’ll learn how to:
- Create and use
OrderedDict
objects in your code - Identify the differences between
OrderedDict
anddict
- Understand the pros and cons of using
OrderedDict
vsdict
With this knowledge, you’ll able to choose the dictionary class that best fits your needs when you want to preserve the order of items.
By the end of the course, you’ll see an example of implementing a dictionary-based queue using OrderedDict
, which would be more challenging if you used a regular dict
object.
[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]
April 11, 2023 at 07:30PM
Click here for more details...
=============================
The original post is available in Planet Python by
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================
Post a Comment