Using OrderedDict in Python (Summary)
For years, Python dictionaries were unordered data structures. This revealed the need for an ordered dictionary that helps in situations where the order of items is important. So Python developers created OrderedDict
, which was specially designed to keep its items ordered.
Python 3.6 introduced a new feature into regular dictionaries. Now they also remember the order of items. With this addition, most Python programmers wonder if they still need to consider using OrderedDict
.
In this video course, you learned:
- How to create and use
OrderedDict
objects in your code - What the main differences are between
OrderedDict
anddict
- What the pros and cons are of using
OrderedDict
vsdict
Now you’re in a better position to make an educated decision on whether to use dict
or OrderedDict
if your code needs an ordered dictionary.
In this course, you coded an example of how to implement a dictionary-based queue, which is a use case that shows that OrderedDict
can still be of value in your daily Python coding adventures.
To continue your learning or review foundational concepts, check out:
- Python Basics: Dictionaries
- Dictionaries in Python
- Custom Python Dictionaries: Inheriting From
dict
vsUserDict
- Sorting a Python Dictionary: Values, Keys, and More
- Python Dictionary Iteration: Advanced Tips & Tricks
- Python Stacks, Queues, and Priority Queues in Practice
- PEP 372 – Adding an ordered dictionary to
collections
- Python documentation:
collections
— Container datatypes
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:00
Summary. Well done. You’ve made it to the end of the course. For years, Python dictionaries were unordered data structures. This revealed the need for an ordered dictionary that helps in situations where the order of items is important. So the Python developers created OrderedDict
, which was specifically designed to keep its items in order.
00:22
Python 3.6 introduced a new feature into regular dictionaries, so they now also remember the order of items. With this addition, most Python programmers wonder if they still need to consider using OrderedDict
.
00:35 But with the knowledge you’ve gained in this course, you should be more informed on this topic.
00:41
In this course, you learned how to create and use OrderedDict
objects in your code, what the main differences are between OrderedDict
and dict
, and what the pros and cons are of using OrderedDict
or dict
.
00:55
You coded an example of implementing a dictionary-based queue, which is a use case that shows that OrderedDict
can still be of value in your daily Python coding adventures.
01:06
Now you’re in a better position to make an educated decision on whether to use dict
or OrderedDict
if your code needs an ordered dictionary.
01:14 We hope you found this course useful, and we’ll see you again soon at realpython.com.
Become a Member to join the conversation.