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 Python Collections (Retired) Dictionaries Managing Keys

Sean Flanagan
Sean Flanagan
33,235 Points

Order of dictionary entries

Hello.

When I input

my_dict['age'] = 41
my_dict

I got

{'age': 41, 'name': 'Sean'}

instead of my name then my age as Kenneth got.

Does anyone know why please?

TIA

Sean :-)

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

Dictionaries aren't like lists where order is important. Since the important thing for a dictionary is to look up a value for a given key, it's stored in a manner that makes that more efficient which isn't necessary the order you place items in.

There also an OrderedDict is the order you put things in is important.

Sean Flanagan
Sean Flanagan
33,235 Points

Thanks Seth. I've up-voted your reply and given it Best Answer.

Sean :-)