You’ve gone from the most basic way to sort a dictionary to a few advanced alternatives that consider performance in sorting key-value pairs.
In this video course, you’ve:
- Reviewed the
sorted()
function - Discovered dictionary views
- Understood how dictionaries are cast to lists during sorting
- Specified sort keys to sort a dictionary by value, key, or nested attribute
- Used dictionary comprehensions and the
dict()
constructor to rebuild your dictionaries - Considered whether a sorted dictionary is the right data structure for your key-value data
You’re now ready to not only sort dictionaries by any criteria you might think of, but also to judge whether the sorted dictionary is the best choice for you.
Share your sorted dictionary use cases and performance comparisons in the comments below!
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.
mikehillsnc on Aug. 13, 2024
Very useful. I have been using .sort() lists and learned the features of sorted()
itemgetter was new to me but I don’t have any immediate application for it
One minor thought - when u mention lambda you might suggest reader stops and tries it for themselves before revealing answer