condense whitespace to single space?

William Park parkw at freewwweb.com
Wed Apr 26 22:25:43 EDT 2000


On Wed, Apr 26, 2000 at 10:57:15PM -0300, k wrote:
> How do I condense the sections of spaces in this string:
> 
> "abc              def         ghi"
> 
> into single spaces?
> 
> "abc def ghi"

1.  string.join(string.split("abc              def         ghi"))

2.  re.sub(' +', ' ', "abc              def         ghi")

--William




More information about the Python-list mailing list