【发布时间】:2015-11-26 03:28:40
【问题描述】:
我有一个列表列表。我想从列表列表中的第二个列表中弹出()一个元素。 这是一个例子:
>>> list1=[1,2]
>>> list2=[3,4]
>>> listoflists=[list1, list2]
所以,打印 listoflists 给了我:
>>>listoflists
[[1, 2], [3, 4]]
我想弹出 listoflists 中第二个列表的第一个元素,即 3。
>>>listoflists.pop([1][0])
给我以下错误;
Traceback (most recent call last):
File "<ipython-input-14-db5dc303028d>", line 1, in <module>
listoflists.pop([0][1])
IndexError: list index out of range
【问题讨论】:
-
listoflists[1].pop()? -
我喜欢人们在 SO 上提问之前为解决问题所付出的努力