Can`t understand loops logic


#1

So, this code write to me next string: "apple cherry berry ". 1st is "apple" but why the second, instead of "berry", is "cherry"?

Sorry for my English. :smiley:

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

for key in d:
    # Your code here!
    print "%s " % d[key]

#2

This has nothing to do with the loop logic, dictionary's are unordered, since you access them by key, there is no reason for dictionaries to be ordered


#3

But why second is "cherry"? Im complete that lesson but dont understand why it work like this.


#4

Because dictionaries are unordered. The order in which you put them, doesn't have to be the order in which order python stores the dictionary


#5

Hmm, many thanks to you.


#6