To iterate over this dictionary (similar to a hash, or map in other languages):
words = {
'a': 'apple',
'b': 'banana',
'c': 'car'
}
you can use the items() method:
for letter, word in words.items():
print('{0}: {1}'.format(letter, word))
The result is:
c: car
a: apple
b: banana
Note the keys are not sorted.
Leave a comment