Python string.join(list) on object array rather than string array

前端 未结 4 553
无人及你
无人及你 2020-11-30 18:17

In Python, I can do:

>>> list = [\'a\', \'b\', \'c\']
>>> \', \'.join(list)
\'a, b, c\'

Is there any easy way to do the s

4条回答
  •  有刺的猬
    2020-11-30 18:47

    You could use a list comprehension or a generator expression instead:

    ', '.join([str(x) for x in list])  # list comprehension
    ', '.join(str(x) for x in list)    # generator expression
    

提交回复
热议问题