This is a similar idea to Green Cloak Guy, but uses a generator rather than creating a list. This should be a little more memory-friendly with large texts and will allow you to iterate over the chunks lazily. You can turn it into a list with list() or use is anywhere an iterator is expected:
s = "Well, Prince, so Genoa and Lucca are now just family estates of the Buonapartes. But I warn you, if you don’t tell me that this means war, if you still try to defend the infamies and horrors perpetrated by that Antichrist—I really believe he is Antichrist—I will have nothing more to do with you and you are no longer my friend, no longer my ‘faithful slave,’ as you call yourself! But how do you do? I see I have frightened you—sit down and tell me all the news."
def get_chunks(s, maxlength):
start = 0
end = 0
while start + maxlength < len(s) and end != -1:
end = s.rfind(" ", start, start + maxlength + 1)
yield s[start:end]
start = end +1
yield s[start:]
chunks = get_chunks(s, 25)
#Make list with line lengths:
[(n, len(n)) for n in chunks]
results
[('Well, Prince, so Genoa', 22),
('and Lucca are now just', 22),
('family estates of the', 21),
('Buonapartes. But I warn', 23),
('you, if you don’t tell me', 25),
('that this means war, if', 23),
('you still try to defend', 23),
('the infamies and horrors', 24),
('perpetrated by that', 19),
('Antichrist—I really', 19),
('believe he is', 13),
('Antichrist—I will have', 22),
('nothing more to do with', 23),
('you and you are no longer', 25),
('my friend, no longer my', 23),
('‘faithful slave,’ as you', 24),
('call yourself! But how do', 25),
('you do? I see I have', 20),
('frightened you—sit down', 23),
('and tell me all the news.', 25)]