【发布时间】:2015-11-14 07:38:40
【问题描述】:
我有一个长字符串,我想将它分成最多 X 个字符的片段。但是,仅在空格处(如果字符串中的某些单词比 X 字符长,则将其放入自己的部分中)。
我什至不知道如何开始这样做...... Python 地
伪代码:
declare a list
while still some string left:
take the fist X chars of the string
find the last space in that
write everything before the space to a new list entry
delete everything to the left of the space
在我编写代码之前,是否有一些 python 模块可以帮助我(我不认为 pprint 可以)?
【问题讨论】:
标签: python algorithm python-3.x text