Arca Arca - 1 year ago 106
Python Question

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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download