输出列表项目和LS一样
我正在尝试输出类似于LS输出的东西。这样的LS命令输出:
file1.txt file3.txt file5.txt
file2.txt file4.txt
但是我此示例列表:
a b c d e f g h i j k l m n o p q r s t u v w x y z
显示为:
a e i m q u y
b f j n r v z
c g k o s w
d h l p t x
在这种情况下,它提供了7列,但我最多想多达8列最大。下一个列表:
a b c d e f g h i j k l m n o p q r s t u v w
必须显示为:
a d g j m p s v
b e h k n q t w
c f i l o r u
和“ ABCDEFG H”,必须按以下显示,因为它已经是1行中的8列,但是:
a b c d e f g h i
将显示为:
a c e g i
b d f h
和::::::
a b c d e f g h i j
a c e g i
b d f h j
I'm trying to output something that resembles as ls output. The ls command outputs like this:
file1.txt file3.txt file5.txt
file2.txt file4.txt
But I this sample list:
a b c d e f g h i j k l m n o p q r s t u v w x y z
to appear as:
a e i m q u y
b f j n r v z
c g k o s w
d h l p t x
In that case, it gave 7 columns which is fine, but I wanted up to 8 columns max. Next the following list:
a b c d e f g h i j k l m n o p q r s t u v w
will have to show as:
a d g j m p s v
b e h k n q t w
c f i l o r u
And "a b c d e f g h" will have to show as is because it is already 8 columns in 1 line, but:
a b c d e f g h i
will show as:
a c e g i
b d f h
And:
a b c d e f g h i j
a c e g i
b d f h j
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法:
columnize
函数首先要通过请求的列数的简单划分列表的简单划分,然后将列表划分为该长度的块,一个一个,一个每个列,最后通过那些为每个列提取当前行元素的订阅者迭代,并将行以空格分隔列表打印出来。One way:
The
columnize
function first figures out how many rows are needed with a simple division of the length of the list by the number of columns requested, then splits the list up into chunks of that length, one per column, and finally iterates through those sublists extracting the current row's element for each column, and prints the row out as a space-separated list.