What's wrond in "Looping over a dictionary"


#1



https://www.codecademy.com/courses/python-beginner-en-cxMGf/2/1?curriculum_id=4f89dab3d788890003000096


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".


#3

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]

#4

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