您最好采用哪种方法来连接序列中的字符串,以便在每两个连续对之间添加一个逗号。 就是说,您如何将例如['a', 'b', 'c']映射到'a,b,c' ? (案例['s']和[]应分别映射到's'和'' 。) 
 我通常最终会使用类似''.join(map(lambda x: x+',',l))[:-1] ,但也会感到有些不满意。 
#1楼
要转换包含数字的列表,请执行以下操作:
string  =  ''.join([str(i) for i in list])
#2楼
这是Python 3.0中允许非字符串列表项的替代解决方案:
>>> alist = ['a', 1, (2, 'b')]
- 标准方式 - >>> ", ".join(map(str, alist)) "a, 1, (2, 'b')"
- 替代解决方案 - >>> import io >>> s = io.StringIO() >>> print(*alist, file=s, sep=', ', end='') >>> s.getvalue() "a, 1, (2, 'b')"
注意:逗号后的空格是故意的。
#3楼
 ",".join(l)不适用于所有情况。 我建议将CSV模块与StringIO一起使用 
import StringIO
import csv
l = ['list','of','["""crazy"quotes"and\'',123,'other things']
line = StringIO.StringIO()
writer = csv.writer(line)
writer.writerow(l)
csvcontent = line.getvalue()
# 'list,of,"[""""""crazy""quotes""and\'",123,other things\r\n'
#4楼
这是清单的例子
>>> myList = [['Apple'],['Orange']]
>>> myList = ','.join(map(str, [i[0] for i in myList])) 
>>> print "Output:", myList
Output: Apple,Orange
更准确的:-
>>> myList = [['Apple'],['Orange']]
>>> myList = ','.join(map(str, [type(i) == list and i[0] for i in myList])) 
>>> print "Output:", myList
Output: Apple,Orange
示例2:
myList = ['Apple','Orange']
myList = ','.join(map(str, myList)) 
print "Output:", myList
Output: Apple,Orange
#5楼
>>> my_list = ['A', '', '', 'D', 'E',]
>>> ",".join([str(i) for i in my_list if i])
'A,D,E'
 my_list可以包含任何类型的变量。 这避免了结果'A,,,D,E' 。 
来源:oschina
链接:https://my.oschina.net/u/3797416/blog/3161103