Python Program to Sort a Dictionary by Value (Sort the dictionary based on values)

bookmark

dt = {5:4, 1:6, 6:3}

sorted_dt = {key: value for key, value in sorted(dt.items(), key=lambda item: item[1])}

print(sorted_dt)

 

Output

{6: 3, 5: 4, 1: 6}