def main():
L=[]
list1=[5,1,3]
list2=[4,6,2]
L.append(list1)
L.append(list2)
f(L)
def f(L):
for i in range(6)
print L[i]
IndexError: list index out of range
最佳答案
您只是将列表附加到 L 上,所以您会得到类似 [[5, 1, 3], [4, 6, 2]] 的内容
。您需要像这样使用 extend
:
L.extend(list1)
L.extend(list2)
print L # [5, 1, 3, 4, 6, 2]
关于python索引错误: 2 lists that are inside a list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5863629/