sort_dict_by_value.py

#! /usr/bin/python3
# ==================================================================
# How to sort a Python dict by value
# ==================================================================

import operator


xs = { 'a':4, 'b':3, 'c':2, 'd':1 }

z1 = sorted(xs.items(), key=lambda x: x[1])

print(z1)


# ---- or


z2 = sorted(xs.items(), key=operator.itemgetter(1))

print(z2)