Sorting a dictionary

Question Q4.3.4

Dictionaries are (before Python 3.6, anyway) data structures without an inherent order. Write a one-line Python statement returning a list of (key, value) pairs sorted by key. Assume that all keys have the same data type (why is this important?) Repeat the exercise to produce a list ordered by dictionary values.


Solution Q4.3.4