How would you make a comma-separated string from a list of strings?

后端 未结 14 1045
北海茫月
北海茫月 2020-11-22 16:07

What would be your preferred way to concatenate strings from a sequence such that between every two consecutive pairs a comma is added. That is, how do you map, for instance

14条回答
  •  死守一世寂寞
    2020-11-22 16:37

    Don't you just want:

    ",".join(l)
    

    Obviously it gets more complicated if you need to quote/escape commas etc in the values. In that case I would suggest looking at the csv module in the standard library:

    https://docs.python.org/library/csv.html

提交回复
热议问题