Python 文件处理与递归算法实践
1. 文件处理练习
1.1 一致行长度格式化
在终端窗口中显示文本时,由于窗口宽度不同,文本行可能过长而换行,导致阅读困难,或者过短而无法充分利用空间。为了解决这个问题,需要编写一个程序,将文件内容进行格式化,使每行尽可能填满。
示例文件内容如下:
Alice was
beginning to get very tired of sitting by her
sister
on the bank, and of having nothing to do: once
or twice she had peeped into the book her sister
was reading, but it had
no
pictures or conversations in it,"and what is
the use of a book," thought Alice, "without
pictures or conversations?"
格式化后,行长度为 50 字符的输出如下:
Alice was beginning to get very tired of sitting
by her sister on the bank, and of having nothing
to do: once or twice she had peeped into the book
her sister was reading, bu
超级会员免费看
订阅专栏 解锁全文
7万+

被折叠的 条评论
为什么被折叠?



