目前,我正在从网络上抓取数据,并希望将其输出为CSV。一切工作正常,但是一旦我在迭代中追加多个列表,该列表的格式就会错误。我从这样的事情开始:list = [a, b, c]list_two = [d, e, f]list_three = [g, h, i]第一次迭代:list = [list, list_two]# list = [[a, b, c], [d, e, f]]第二次迭代:list = [list, list_three]我得到:# list = [[[a, b, c], [d, e, f]], [g, h, i]]我希望有:# list = [[a, b, c], [d, e, f], [g, h, i]]请帮我!我想这是一件容易的事,但我不明白。而且我实际上很难找到有关如何附加列表的信息。
2 回答

小唯快跑啊
TA贡献1863条经验 获得超2个赞
只需使用+连接两个列表:
list = [ list, list_two ]
list += [ list_three ]
您还可以使用append:
list = [ list ]
list.append( list_two )
list.append( list_three )

慕桂英3389331
TA贡献2036条经验 获得超8个赞
您可以创建一个助手列表并使用append:
例如
helperList = []
list = ['a', 'b', 'c']
list_two = ['d', 'e', 'f']
list_three = ['g', 'h', 'i']
helperList.append(list)
helperList.append(list_two)
helperList.append(list3_three)
#helperList >>> [['a', 'b', 'c'], ['d', 'e', 'g'], ['g', 'h', 'i']]
添加回答
举报
0/150
提交
取消