按key排序遍历字典
for key in sorted(dic,key=None,reverse=False):
按value排序遍历字典
for key in sorted(dic,key=lamda kv:kv[1],reverse=False):
按value中某一项遍历输出数组,下面按照date日期由新到旧排序
其实是把原字典中的date单独作为数组提出来
for key in sorted([v['date'] for v in dic.values()],key=None,reverse=True):
如果需要进行删除等操作需要获得key索引
dicTmp = {v['date']:k for k,v in dic.items()}
for key in sorted(dicTmpData,key=None,reverse=True):
del dic[dicTmp[key]]
升级写法:
for key, value in sorted(dicAllData.items(), key=lambda kv:kv[1]['date'],reverse=True):