python - 根据指定的键值对所有嵌套字典进行排序并返回
问题描述
我正在尝试重新排列嵌套字典的内容,它将检查指定键的值。
dict_entries = {
'entries': {
'AzP746r3Nl': {
'uniqueID': 'AzP746r3Nl',
'index': 2,
'data': {'comment': 'First Plastique Mat.',
'created': '17/01/19 10:18',
'project': 'EMZ',
'name': 'plastique_varA',
'version': '1'},
'name': 'plastique_varA',
'text': 'plastique test',
'thumbnail': '/Desktop/mat/plastique_varA/plastique_varA.jpg',
'type': 'matEntry'
},
'Q2tch2xm6h': {
'uniqueID': 'Q2tch2xm6h',
'index': 0,
'data': {'comment': 'Camino from John Inds.',
'created': '03/01/19 12:08',
'project': 'EMZ',
'name': 'camino_H10a',
'version': '1'},
'name': 'camino_H10a',
'text': 'John Inds : Camino',
'thumbnail': '/Desktop/chips/camino_H10a/camino_H10a.jpg',
'type': 'ChipEntry'
},
'ZeqCFCmHqp': {
'uniqueID': 'ZeqCFCmHqp',
'index': 1,
'data': {'comment': 'Prototype Bleu.',
'created': '03/01/19 14:07',
'project': 'EMZ',
'name': 'bleu_P23y',
'version': '1'},
'name': 'bleu_P23y',
'text': 'Bleu : Prototype',
'thumbnail': '/Desktop/chips/bleu_P23y/bleu_P23y.jpg',
'type': 'ChipEntry'
}
}
}
在我上面的嵌套字典示例中,我试图通过name
andcreated
键(每个 2 个函数)检查它,一旦它被排序,index
值也会相应地更新......
即便如此,我还是能够查询所述键的值:
for item in dict_entries.get('entries').values():
#The key that I am targetting at
tar_key = item['name']
但这正在返回name
键的值,我不确定下一步,因为我正在尝试name
按键的值进行排序并捕获+重新排列嵌套字典的所有内容。
这是我想要的输出(如果检查name
):
{'entries': {
'ZeqCFCmHqp': {
'uniqueID': 'ZeqCFCmHqp',
'index': 1,
'data': {'comment': 'Prototype Bleu.',
'created': '03/01/19 14:07',
'project': 'EMZ',
'name': 'bleu_P23y',
'version': '1'},
'name': 'bleu_P23y',
'text': 'Bleu : Prototype',
'thumbnail': '/Desktop/chips/bleu_P23y/bleu_P23y.jpg',
'type': 'ChipEntry'
}
'Q2tch2xm6h': {
'uniqueID': 'Q2tch2xm6h',
'index': 0,
'data': {'comment': 'Camino from John Inds.',
'created': '03/01/19 12:08',
'project': 'EMZ',
'name': 'camino_H10a',
'version': '1'},
'name': 'camino_H10a',
'text': 'John Inds : Camino',
'thumbnail': '/Desktop/chips/camino_H10a/camino_H10a.jpg',
'type': 'ChipEntry'
},
'AzP746r3Nl': {
'uniqueID': 'AzP746r3Nl',
'index': 2,
'data': {'comment': 'First Plastique Mat.',
'created': '17/01/19 10:18',
'project': 'EMZ',
'name': 'plastique_varA',
'version': '1'},
'name': 'plastique_varA',
'text': 'plastique test',
'thumbnail': '/Desktop/mat/plastique_varA/plastique_varA.jpg',
'type': 'matEntry'
}
}
}
解决方案
推荐阅读
- c# - 使用带有外部 Azure KeyVault (HSM) 密钥的 BouncyCastle 创建证书时签名无效
- jquery - 如何将引导切换器默认设置为 ON?
- jupyter-notebook - 在 JUPYTERLAB Azure ML Studio 中打开笔记本时出现 ERR_HTTP2_PROTOCOL_ERROR
- react-router - 如何从 Docusuarus 页脚链接到非 Docusaurus 定义的路线?
- sql - SQL 命令未正确结束添加必须限制要显示的数据集
- sql - 在本地数据库中存储 OAuth 用户信息(用户名、名字、姓氏等)
- r - 如何使用此数据集在 R 中执行滚动回归?
- python - 如何从字符串中删除 ('')
- symfony - 如何使用 webpack 在 symfony 项目中为数据表库设置修复头
- load - 如何检查从 aws S3 到雪花的数据加载结果