items()
to iterate over a dictionary PTC-W0011The preferred way to iterate over the key-value pairs of a dictionary is to declare two variables in a for loop, and then call dictionary.items()
(or dictionary.iteritems()
for Python2), where dictionary is the name of your variable representing a dictionary.'
details = {"first_name": "Alfred", "last_name":"Hitchcock"}
for key in details.keys():
print(key, d[key])
details = {"first_name": "Alfred", "last_name":"Hitchcock"}
for key, value in details.items():
print(key, value)