我在Python中有一個列表。該列表中有子列表。 例如:在Python中刪除字符串中每個元素的第一項
[['85.', 'Document', 'will', 'discuss', 'allegations,', 'or', 'measures', 'being', 'taken', 'against,', 'corrupt', 'public', 'officials', 'of', 'any', 'governmental', 'jurisdiction', 'worldwide.'], ['56.', 'Document', 'will', 'include', 'a', 'prediction', 'about', 'the', 'prime', 'lending', 'rate,', 'or', 'will', 'report', 'an', 'actual', 'prime', 'rate', 'move.'], and so on]
當我打印MYLIST [0],我得到如下:
['85.', 'Document', 'will', 'discuss', 'allegations,', 'or', 'measures', 'being', 'taken', 'against,', 'corrupt', 'public', 'officials', 'of', 'any', 'governmental', 'jurisdiction', 'worldwide.']
當我打印MYLIST [0] [0]我得到85.
我新的python和我不明白如何訪問這些值(85,56,等等)內循環,以便我可以刪除所有的數字。即85,56等等。
- 我也有一個類似的列表
[[1, 23], [2, 34], [3, 45], [1, 45], [2, 44]]
,我想添加的所有的第二元件,其中第1個要素是相同的。即我想增加23 + 45(因爲兩者都有1作爲他們的第一個元素)。我知道我需要一個for循環,但我是python的新手,我無法理解循環。
在你提出關於SO的基本問題之前,請閱讀[documentation](http://docs.python.org/tutorial/index.html)。它涵蓋了你剛剛提到的一切。 – 2012-02-05 22:39:59