Apple, Cherry, Berry - Printing out of order?


I'm on lesson 14. Looping Over a Dictionary. I've completed the exercise successfully, but something has come out a little funny; the fruit aren't printing in the order they're listed. I'm interested to know why.

Instead of printing apple, berry, cherry, I'm getting apple, cherry, berry. Why is this? Do I need to explicitly instruct it to print in the given order?

dictionary = {'a': 'apple', 'b': 'berry', 'c': 'cherry'}

for key in dictionary:
    print key, dictionary[key]


dictionaries are generally accessed by key, not by index, so they are unordered from nature


disclaimer: in python3.6 dictionaries are ordered, i am not sure why yet, haven't looked into it. Just posting in case someone is going to ask this


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.