Python, print delimited list

前端 未结 8 1305
小鲜肉
小鲜肉 2020-12-02 16:55

Consider this Python code for printing a list of comma separated values

for element in list:
    print element + \",\",

What is the preferr

相关标签:
8条回答
  • 2020-12-02 17:38

    That's what join is for.

    ','.join([str(elem) for elem in a])
    
    0 讨论(0)
  • 2020-12-02 17:49
    >>> ','.join(map(str,a))
    '1,2,3'
    
    0 讨论(0)
提交回复
热议问题