Iterating Over an OrderedDict
and values of an
OrderedDict object. Regular dictionaries also support reverse iteration. However, if you try to use
reversed() with a regular dictionary object in a Python version lower than 3.8, then you get a
If you need to iterate over the items in a dictionary in reverse order, then
OrderedDict is a good ally. Using a regular dictionary dramatically reduces your backwards compatibility because reverse iteration wasn’t added to regular dictionaries until Python 3.8. In the next section of the course, you’ll take a look at some of the unique features of
Become a Member to join the conversation.