You need an ordered data type to represent the sorted values (probably a list of tuples) as it's not possible to sort a directory because they are orderless whereas list and tuples aren't. Ex.
import operator
y = {2: 3, 4: 5, 5: 4, 3: 2, 1: 1}
sorted_y = sorted(y.items(), key=operator.itemgetter(1))
A list of tuples, here sorted_x will be sorted by first element in each tuple dict(sorted_y) == y
If you want to sort the keys instead of values, use
import operator
y = {2: 3, 4: 5, 5: 4, 3: 2, 1: 1}
sorted_y = sorted(y.items(), key=operator.itemgetter(1))
Hope this helps.
P.S. Only works in the Python versions below 3.0
Learn in detail about Python by enrolling in Intellipaat Python Course online and upskill.