print two dimensional list

后端 未结 7 2504
[愿得一人]
[愿得一人] 2021-02-20 14:46

I have a list, in which is another list and I want to doc.write(a)

a = [[1, 2, \"hello\"],
     [3, 5, \"hi There\"],
     [5,7,\"I don\'t know\"]]
         


        
7条回答
  •  爱一瞬间的悲伤
    2021-02-20 15:22

    I was looking for an answer to this as well. After reading the comments here, this is what I came up with:

    I was looking for an answer to this as well. After reading the comments here, this is what I came up with:

    ','.join(str(' '.join(str(x) for x in v)) for v in a)
    

    This creates something like:

    1 2 hello,3 5 hi There,5 7 I don't know
    

    If you want all spaces as delimiters, then use ' ' instead of ',' at the front.

提交回复
热议问题