我有一个代码的示例输出。在这里,我想提取具有最高分数的类名。我可以设置阈值来收集大于阈值的类名。但它无助于解决问题。
"classes": [
{
"score": 0.059986,
"class": "box"
},
{
"score": 0.0442621,
"class": "Duster"
},
{
"score": 0.931077,
"class": "Multimeter"
},
{
"score": 0.203139,
"class": "sellotape"
}
],
请帮助编写一个python脚本来解决这个问题。
答案 0 :(得分:0)
all_classes = {"classes": [
{
"score": 0.059986,
"class": "box"
},
{
"score": 0.0442621,
"class": "Duster"
},
{
"score": 0.931077,
"class": "Multimeter"
},
{
"score": 0.203139,
"class": "sellotape"
}
]}
print max(all_classes['classes'], key=lambda x: x["score"])
{'score': 0.931077, 'class': 'Multimeter'}