Convert Python List to a Delimited String

This is easy to do with the join command, though the syntax may not be immediately obvious.

So if you create a list:


x = ["abc","def","ghi","jkl"]

And wanted to convert that to a comma-separated list (for example, to store in a file), you would do this:


",".join(x)

And it would result in:


'abc,def,ghi,jkl'

Or if you wanted it to be a tab-delimited string, you would do this:


"\t".join(x)

Leave a Reply