簡體   English   中英

在 Python 中以垂直格式打印列表的所有元素

[英]Printing all elements of a list in vertical format in Python

我想以垂直格式打印列表A的所有元素。 我展示當前和預期的 output。

A=[[1, 2, 3, 4, 5, 6, 7, 8, 10],[15,19,21,11,18]]
print(*A)

當前output是

[1, 2, 3, 4, 5, 6, 7, 8, 10] [15, 19, 21, 11, 18]

預期的 output 是

[[1, 
  2, 
  3, 
  4, 
  5, 
  6, 
  7, 
  8, 
  10],
  [15, 
   19, 
   21, 
   11, 
   18]]

您可以像這樣使用print

print(
    '[[', '],\n['.join(
        [str(',\n'.join(
            [str(i) for i in j]
        )) for j in A]
    ),
    end=']]',
    sep=''
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM