Print a nested list line by line - Python

后端 未结 7 1545
-上瘾入骨i
-上瘾入骨i 2020-12-15 12:51

A = [[1, 2, 3], [2, 3, 4], [4, 5, 6]]

I am trying my best to print A of the form:

1 2 3
2 3 4
4 5 6

That

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-15 13:39

    If you are in Python 3.x:

    print(*('{} {} {}'.format(*r) for r in A), sep='\n')
    

    or:

    print(*('%d %d %d' % tuple(r) for r in A), sep='\n')
    

    If not, you can import Python 3.x's print function from the __future__ module.

提交回复
热议问题