简体   繁体   中英

Python combine 2 lists of strings for CSV

I have two lists that I want to combine for csv output:

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

However, I want the output for the csv to format like this:

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. 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' .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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