gpt4 book ai didi

python - 访问字典中数组中嵌套的数据

转载 作者:行者123 更新时间:2023-11-30 23:33:08 25 4
gpt4 key购买 nike

我感到困惑并寻求帮助。我正在尝试访问存在于字典内部的数据,该字典位于字典内部的数组内部。见下文:

{
'files': [
{
'type': 'diskDescriptor',
'name': '[VM] VM1/VM1.vmdk',
'key': 4,
'size': 0
},
{
'type': 'diskExtent',
'name': '[VM] VM1/VM1-flat.vmdk',
'key': 5,
'size': 32457621504
}
],
'capacity': 32505856,
'label': 'Hard disk 1',
'descriptor': '[VM] VM1/VM1.vmdk',
'committed': 31696896,
'device': {
'summary': '32,505,856 KB',
'_obj': <pysphere.vi_property.VIProperty object at 0x17442910>,
'unitNumber': 0,
'key': 2000,
'label': 'Hard disk 1',
'type': 'VirtualDisk',
'capacityInKB': 32505856
}
}

如果我想访问,比如说描述符键值,我将如何使用 Python 来实现这一点?由于某种原因,我尝试过的所有组合都不起作用。

任何帮助和指导将不胜感激,如果需要更多信息,我可以提供。谢谢。

最佳答案

我们称你的主词典为 bob,因为我喜欢 bob:

bob['files'] #get you the list with second dictionary

bob['files'][0] #get you the first item in the list, which is the nested 2nd dictionary

bob['files'][0]['type'] == 'diskDescriptor'

关于python - 访问字典中数组中嵌套的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19096773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com