私信  •  关注

Ahmad Anis

Ahmad Anis 最近创建的主题
Ahmad Anis 最近回复了

您可以创建一个函数,该函数可以返回所需长度的块。

In [13]: def split(N, text):
    ...:     chunks = [text[i:i+N] for i in range(0, len(text), N-1)]
    ...:     return chunks

这将以列表的形式返回块。即

text = "Lorem.................." # complete lorem ispm
chunks = split(250, text)
print(len(s[0]), len(s[1]), len(s[2]))

输出长度为

250 250 50