标签: python python-3.x
列表:
['a','b']
预期清单:
['a,b']
有没有pythonic的方法来做到这一点?
答案 0 :(得分:1)
l2 = [','.join(l)]
但是,将此输出包装在列表中并不重要。获得字符串可能更有意义:
joined_string = ','.join(l)
答案 1 :(得分:0)
您可以使用str.join
str.join
>>> l = ['a','b'] >>> [', '.join(l)] ['a, b']