Sort dictionary by key
Sorts the given dictionary by key.
- Use
dict.items()to get a list of tuple pairs fromdand sort it usingsorted(). - Use
dict()to convert the sorted list back to a dictionary. - Use the
reverseparameter insorted()to sort the dictionary in reverse order, based on the second argument.