我查看了其他一些答案,但我并不完全明白。没有重复的值。
{ "type":"champion",
"data":{
"89":{
"title":"the Radiant Dawn",
"name":"Leona"
},
"110":{
"title":"the Arrow of Retribution",
"name":"Varus"
}
}
}
我拥有什么,我不确定如何继续。在实际的词典中,除了标题和键之外,还有更多的信息
championID = 0
for key, value in championData["data"].items():
for childkey,childvalue in value.items():
#
champion = getChamp(championID)
我想输入一个名字并让它返回ID(列出了数字89和110)。例如,输入Leona将返回89。
(对不起,我本可以在开头问这个问题做得更好:' v)
答案 0 :(得分:1)
这将有效:
championData = {"type": "champion", "data": {
"89": {
"title": "the Radiant Dawn",
"name": "Leona"
},
"110": {
"title": "the Arrow of Retribution",
"name": "Varus"
}
}}
name = "Leona"
data = championData['data']
for championId in data:
if(data[championId]['name']) == name:
print(championId)
输出为:89