【发布时间】:2021-01-29 12:22:48
【问题描述】:
假设我有以下 json 文件。使用 data1["tenants"][1]['name'] 我可以选择 uniquename2。有没有办法通过遍历文档来收集“1”数字?
{
"tenants": [{
"key": "identifier",
"name": "uniquename",
"image": "url",
"match": [
"identifier"
],
"tags": [
"tag1",
"tag2"
]
},
{
"key": "identifier",
"name": "uniquename2",
"image": "url",
"match": [
"identifier1",
"identifier2"
],
"tags": ["tag"]
}
]
}
简而言之:data1["tenants"][1]['name']= 唯一名称2 data1["tenants"][0]['name'] = 唯一名称
我怎样才能找出哪个号码有哪个名字。那么如果我有 uniquename2 对应的数字/索引是什么?
【问题讨论】:
标签: python json dictionary indexing dictionary-comprehension