What's wrond in "Looping over a dictionary"



Hi! Can someone help me and explain me what's wrong with my code?

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

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

But system shows "Oops, try again. It looks like your code did not print "b berry".


This will print,

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

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

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

Try using,

print key, d[key]


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