14. Looping over a dictionary


#1

My code doesn't work like this:
I get this error: Oops, try again. It looks like your code did not print "b berry".
Is it because it doesnt get printed as a string?

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

for key in d:
# Your code here!
if d[key] == 'berry':
print key, d[key]


#2

You do not need the if statement. The purpose of the program is to print the WHOLE dictionary. Remove that if, and it should work!


#5

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