Why aren’t the values added to the dictionary in order?


#1

Question

Why aren’t the values added to the dictionary in order?

Answer

In Python, a dictionary doesn’t add your items in the order you might expect. If we added 3 dishes, Burger, Salad, and Sammich, we’d expect them to appear in that order. But we’d be wrong!
There’s an advanced reason behind it, and like anything in programming, it’s because of efficiency. For now, just know that adding things to a dictionary does not add it in an order you’d expect, or necessarily at the end of the dictionary.


FAQLearn Python: Python Lists and Dictionaries - New Entries