对key值进行排序
dic = {'a': 19, 'c': 199,'g': 2, 'e': 99, 'd': 100}
sorted_by_key = sorted(dic.items(), key=lambda x: x[0])
若要对它进行倒序排序,只需在后面加上reverse=Ture即可
执行后变成列表嵌套元组
对value值进行排序
sorted_by_value = sorted(dic.items (),key=lambda x:x[1])
若要对它进行倒序排序,只需在后面加上reverse=Ture即可
执行后变成列表嵌套元组