0

我有我的一个代码的示例输出。在这里,我想提取得分最高的班级名称。我可以设置阈值来收集大于阈值的类名。但这无助于解决问题。

 "classes": [
        {

          "score": 0.059986,
          "class": "box"
        },
        {
          "score": 0.0442621,
          "class": "Duster"
        },
        {
          "score": 0.931077,
          "class": "Multimeter"
        },
        {
          "score": 0.203139,
          "class": "sellotape"
        }
      ],

请帮助编写一个python脚本来解决这个问题。

4

1 回答 1

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'}
于 2017-01-20T12:25:40.130 回答