Print a nested list line by line - Python

后端 未结 7 1549
-上瘾入骨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:33

    for [a,b,c] in A:
       print(a,b,c)
    

    This might help. But if you have more number of elements in the lists or if elements in the nested lists are variable,This won't work. Below code will print all elements in a nested line in single line.

    for b in A:
        for p in b:
             print(p,end=" ")
        print()
    

提交回复
热议问题