我試圖刪除「標題」元素從這個名單中,我從網上刮:Unlisting Python列表和刪除元素
x =
[[(u'title', u'Goals for')], [(u'title', u'Goals against')], [(u'title', u'Penalty goal')], [(u'title', u'Goals for average')], [(u'title', u'Matches Played')], [(u'title', u'Shots on goal')], [(u'title', u'Shots Wide')], [(u'title', u'Free Kicks Received')], [(u'title', u'Offsides')], [(u'title', u'Corner kicks')], [(u'title', u'Wins')], [(u'title', u'Draws')], [(u'title', u'Losses')]]
我想我最終是
result = ['Goals for', 'Goals against','Penalty goal','Goals for average',....]
但我可以做 y = x[1][0][1]
=>「爲目標的」我不能這樣做x[i][0][1]
,因爲它是指數我的循環語句中我得到了錯誤
TypeError: list indices must be integers, not tuple
我該如何解決這個問題?
你listcomp會產生一堆空列表。 :^) – DSM
好,DSM!我沒有注意到第三層嵌套。 ;) – SimonT