14/19 Explanation of why this works


I successfully completed this lesson, however I do not really understand why it works. To be honest, it was somewhat of an educated lucky guess. I presumed it would have printed the same value twice.

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

for key in d:

Your code here!

print key, d[key]


Dictionaries contain key-value pairs. We access the key directly, but to access the value, we use a subscript on the object.

a   : 'apple'
key    value


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