[issue26214] textwrap should minimize number of breaks in extra long words

2021-12-27 Thread Andrei Kulakov


Andrei Kulakov  added the comment:

It may be worth fixing wrap() to do the nicer style of wrapping for long words. 
If we decide to do that, it should be done via a new parameter because the same 
logic (TextWrapper class) is used for `shorten` and in that case it may be 
preferable to have the chunk of longer word rather than cutting it out entirely.

--
nosy: +andrei.avk
versions: +Python 3.10, Python 3.11, Python 3.9 -Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26214] textwrap should minimize number of breaks in extra long words

2020-09-19 Thread Georg Brandl


Change by Georg Brandl :


--
nosy:  -georg.brandl

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26214] textwrap should minimize number of breaks in extra long words

2020-09-19 Thread Irit Katriel


Change by Irit Katriel :


--
components: +Library (Lib)

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26214] textwrap should minimize number of breaks in extra long words

2020-09-04 Thread Irit Katriel


Irit Katriel  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26214] textwrap should minimize number of breaks in extra long words

2020-09-04 Thread Irit Katriel


Irit Katriel  added the comment:

One more wrap: 

>>> wr(' '.join(itertools.chain(*(wr(x, 5) for x in wr("123 123 1234567 12", 
>>> width=5, break_long_words=False, 5)
['123', '123', '12345', '67 12']

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26214] textwrap should minimize number of breaks in extra long words

2020-09-04 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

The code with nested wraps is awesome. But it does not work well.

>>> list(itertools.chain(*(wr(x, 5) for x in wr("123 123 1234567 12", width=5, 
>>> break_long_words=False
['123', '123', '12345', '67', '12']

It is expected that '67' and '12' should be in the same line: '67 12'.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26214] textwrap should minimize number of breaks in extra long words

2020-09-04 Thread Irit Katriel


Irit Katriel  added the comment:

You can do this already with the break_long_words arg of testwrap:

>>> import itertools, textwrap
>>> wr = textwrap.wrap
>>> list(itertools.chain(*(wr(x, 5) for x in wr("123 123 1234567", width=5, 
>>> break_long_words=False
['123', '123', '12345', '67']

--
nosy: +iritkatriel

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26214] textwrap should minimize number of breaks in extra long words

2018-09-21 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26214] textwrap should minimize number of breaks in extra long words

2016-02-11 Thread Steven D'Aprano

Changes by Steven D'Aprano :


--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26214] textwrap should minimize number of breaks in extra long words

2016-01-29 Thread Terry J. Reedy

Changes by Terry J. Reedy :


--
type: behavior -> enhancement
versions:  -Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26214] textwrap should minimize number of breaks in extra long words

2016-01-27 Thread SilentGhost

Changes by SilentGhost :


--
nosy: +georg.brandl
versions: +Python 3.6 -Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26214] textwrap should minimize number of breaks in extra long words

2016-01-27 Thread Tuomas Salo

Changes by Tuomas Salo :


--
title: textwrap should minimize breaks -> textwrap should minimize number of 
breaks in extra long words

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com