我有以下示例數據作爲python中的listobject。如何刪除列表中的多個字典中的鍵python
[{'itemdef': 10541,
'description': 'Dota 2 Just For Fun tournament. ',
'tournament_url': 'https://binarybeast.com/xDOTA21404228/',
'leagueid': 1212,
'name': 'Dota 2 Just For Fun'},
{'itemdef': 10742,
'description': 'The global Dota 2 league for everyone.',
'tournament_url': 'http://www.joindota.com/en/leagues/',
'leagueid': 1640,
'name': 'joinDOTA League Season 3'}]
如何從此列表中刪除說明tour_url;或者我怎麼能只保留名字和聯盟鍵。我嘗試了各種解決方案,但它似乎並不奏效。
第二個問題:如何過濾這個列表?如在mysql中:
select *
from table
where leagueid = 1212
請把我當成一個像python一樣的新人,因爲我真的是。
是否存在'del'和'item.pop'之間的區別? – rassar
等等,所以我有一個詞典列表?該死,非常感謝。我一直被困在這個狗屎上。 – Adam
@rassar'item.pop('key')'也會返回密鑰的值,所以當我們需要讀取和刪除對象時使用它。 – Pavel