简体   繁体   English

Python结合了2个CSV字符串列表

[英]Python combine 2 lists of strings for CSV

I have two lists that I want to combine for csv output: 我有两个列表要合并为csv输出:

alist = ['a', 'b', 'c']
blist = ['d', 'e', 'f']

However, I want the output for the csv to format like this: 但是,我希望csv的输出格式如下:

clist = ['a', 'b', 'c', 'd e f']

such that the last entry extended of the list contains the list of "blist", but will not be comma separated. 这样,列表的最后扩展条目包含“ blist”列表,但不会用逗号分隔。 Unfortunately, what I have been trying instead gives me: 不幸的是,我一直在尝试给我:

clist =  ['a', 'b', 'c', 'def']

Is this what you are after? 这是你所追求的吗?

 clist = alist + [" ".join(blist)]

otherwise I think what you are after doesn't make sense, or you need to explain better what you want... Given python syntax, 'x' 'y' 'z' is 'xyz' . 否则,我认为您追求的是没有意义的,或者您需要更好地解释您想要的东西...给定python语法, 'x' 'y' 'z' 'xyz'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM