我正在使用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_將成爲列表中的最後一項。 –