Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

What is the purpose and main benefit(s) of Using OrderedDict?

I understand that OrderedDict will preserve the order of the dict as it was created so that the list shown to the users will always be the same.

But as I tried: 1. using OrderedDict, just like using regular dict which is non-indexed, I still cannot use index to iter through it...(I though as it is ordered, it should have this functionality)

for i in range(len(od)):
    print(od[i])

2. If I use a regular list like this:

menu = {
    'a':add_entry,
    'v':view_entries,
    's':search,
    'd':delete,
}

the output of the diary app will still be the same as the OrderedDict one and doesn't seem to change..

So what is the main benefit of using OrderedDict in the real world? Some examples would be much appreciated!!