First thing first the Standard Python dictionaries are unordered. So, even if you sorted the (key, value) pairs, you wouldn't be able to store them in a dict in a way that would preserve the ordering.
So, the easiest way of sorting a dictionary by key is to use OrderedDict, which remembers the order in which the elements have been inserted:
The following example illustrates how we will use the ordered dictionary:-
import collections
d = {2:3, 1:89, 4:5, 3:0}
od = collections.OrderedDict(sorted(d.items()))
od
To know more about this you can have a look at the following video tutorial:-