我正在使用SFG WorldCup API的JSON数据。如何查找JSON列表中的哪个项目对于Python中的给定属性具有最大值?
我需要做的是找出给定比赛中给定球队得分的最新进球。要做到这一点,我需要按照away_team_events
属性的属性数组的每个元素中的attribute
键的值进行排序。
让我来说明一下。
下面是法国从正在进行的(写作的时候)法国v瑞士的法国样本JSON。
"away_team_events": [
{
"id": 276,
"type_of_event": "goal",
"player": "Giroud",
"time": "17"
},
{
"id": 277,
"type_of_event": "goal",
"player": "Matuidi",
"time": "18"
},
{
"id": 278,
"type_of_event": "penalty-wrong",
"player": "Benzema",
"time": "32"
},
{
"id": 279,
"type_of_event": "goal",
"player": "Valbuena",
"time": "40"
},
{
"id": 281,
"type_of_event": "substitution-in",
"player": "Pogba",
"time": "63"
},
{
"id": 282,
"type_of_event": "substitution-in",
"player": "Koscielny",
"time": "66"
},
{
"id": 283,
"type_of_event": "goal",
"player": "Benzema",
"time": "67"
}
]
所以我需要做的就是找到其中“id”属性是最大的,因为这将是最新的目标。
如何按这样的特定属性排序?我看过this question,但我真的无法理解答案。
编辑:换句话,抱歉的混乱。
我不需要重新排列它们,但是如何确定列表中的哪个项目具有最大的id,并使用它?
但它似乎已经排序。 – Fabricator
@ChristianBerendt:这是*字典列表*。 –
它已经是一个列表,并假设其已填充生活,那么它将按照实际事件的顺序;所以最后的_event_将成为列表中的最后一项。 –