|
Dictionaries and LoopsTo obtain a list of the keys in a dictionary, use the keys function. keys can be used with the for statement to process each element of the dictionary in turn:
When you run this code, the output is similar to this:
Note that the elements of the dictionary are displayed in no particular order. To sort the keys in alphabetical order, use sort:
|