[Python-Dev] textwrap and unicode

Fredrik Lundh fredrik@pythonware.com
Tue, 22 Oct 2002 22:04:25 +0200


greg wrote:
> But I still don't know how to replace all whitespace with
> space

string.join(phrase.split(), " ")

or

re.sub("(?u)\s+", " ", phrase)

not sure which one's faster; I suggest benchmarking.

(if you want to preserve leading/trailing space with the split
approach, use isspace on the start/end of phrase)

> or detect words that end with a lowercase letter.

word[-1].islower()

</F>