Sorting a dictionary

Question Q4.3.4

Dictionaries are data structures in which (since Python 3.6) key-value pairs are stored in order of insertion. Write a one-line Python statement returning a list of (key, value) pairs sorted by the keys themselves. 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