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 trialSean Flanagan
33,235 PointsOrder 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
56,413 PointsDictionaries 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
33,235 PointsSean Flanagan
33,235 PointsThanks Seth. I've up-voted your reply and given it Best Answer.
Sean :-)