回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有一个嵌套字典,看起来像这样:</p>
<pre><code>{'Div 4 A Herrar': {'0': {'awayScore': '0',
'awayTeam': 'Floda BoIF',
'events': [],
'homeScore': '0',
'homeTeam': 'SKIF Semberijaaaah',
'tempTime': '10:00',
'time': 'FT'},
'1': {'awayScore': '0',
'awayTeam': 'Kode IF',
'events': [{'eventID': '3215',
'eventScore': '1-0',
'eventTime': 'HT',
'eventType': 'Goal-timocin',
'name': 'timocin',
'selectedTeam': 'homeTeam'},
{'eventID': '2312',
'eventScore': '2-0',
'eventTime': 'HT',
'eventType': 'Goal-timocin',
'name': 'timocin',
'selectedTeam': 'homeTeam'}],
'homeScore': '2',
'homeTeam': 'Partille IF FK',
'tempTime': '11:00',
'time': 'FT'},
'2': {'awayScore': '0',
'awayTeam': 'Romelanda UF',
'events': [],
'homeScore': '0',
'homeTeam': 'IK Kongah\\u00e4lla',
'tempTime': '12:00',
'time': 'FT'}}}
</code></pre>
<p>我想做的是删除<strong>事件列表中的特定事件。我事先知道的是前两个键的含义:</p>
<pre><code>"Div 4 A Herrar" and the integer number that represents a dictionary item
</code></pre>
<p>对于需要删除的事件,我还有<strong>eventID</strong>。你知道吗</p>
<p>例如,为了让您更清楚,让我们假设我想要删除一个EventID3215的事件。然后我就可以删除这些信息:</p>
<pre><code>"Div 4 A Herrar", 1, 3215'
</code></pre>
<p>如果有什么不清楚,请一定要问,我会更新我的问题,以更具体。你知道吗</p>
<p>编辑1</p>
<p>我只能这样想:</p>
<pre><code>for event in dict["Div 4 A Herrar"][1]["events"]:
if(event["eventID"] == "3215"):
# this is where i got stuck since i had no idea how to proceed from here.
</code></pre>