为了账号安全,请及时绑定邮箱和手机立即绑定

在Python中为CSV输出附加列表

在Python中为CSV输出附加列表

守着一只汪 2021-03-01 15:20:15
目前,我正在从网络上抓取数据,并希望将其输出为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 )


查看完整回答
反对 回复 2021-03-26
?
慕桂英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']]


查看完整回答
反对 回复 2021-03-26
  • 2 回答
  • 0 关注
  • 150 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号