用python处理数据时,经常需要根据字典的键值进行排序。简单记录下sorted 函数的键值排序用法。 1.操作对象 一个list,其中的元素均为字典 a = { 'ID': 2, 'score': 70} b = { 'ID': 3, 'score': 90} c = { 'ID': 1, 'score': 80} data = [a, b, c] # [{'ID': 2, 'score': 70}, {'ID': 3, 'score': 90}, {'ID': 1, 'score': 80}] 2.键值排序 # 1.针对‘score’ data_sorted =