Irit Katriel <[email protected]> added the comment:
To clarify, this solution is a linear-time greedy one, with three passes:
- the first pass puts each long word on its own line.
- the second pass chops them up into words of at most width characters.
- the third pass wraps them, when there are no more long words.
This minimizes the number of breaks within words. It doesn't minimize the
number of output lines (you'd need a dynamic programming programming algo for
that - O(n^2)). So for this input:
wr("123 12 123456 1234", 5)
you will get
['123', '12', '12345', '6', '1234']
where you may (or may not) have preferred:
['123', '12 1', '23456', '1234']
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue26214>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com