python多维字典排序
sjp = json.loads(jres) sjpsort = sorted(sjp, key=lambda x:float(sjp[x]['ubuy']),reverse = False) #根据Ubuy排序出键值 newsjp = {} for j in sjpsort: #将新的键值插入到newsjp if sjp[j]['ubuy'] != 0: #过滤条件 newsjp[j] = sjp[j] sjp = newsjp
简单的案例
a = {"阳": {"math": "88", "chinese": "90", "english": "80"},"伟": {"math": "98", "chinese": "80", "english": "77"},\ "楠": {"math": "85", "chinese": "94", "english": "30"},"泡": {"math": "66", "chinese": "77", "english": "74"},\ "骥": {"math": "13", "chinese": "10", "english": "20"}} EnglishTop3 = sorted(a, key=lambda x:int(a[x]['english']),reverse = True)[0:3] for student in EnglishTop3: print student
Lambda函数 介绍 https://www.cnblogs.com/evening/archive/2012/03/29/2423554.html
参考文章 https://blog.csdn.net/adooadoo/article/details/8365509