Suppose this string:
The fox jumped over the log.
Turning into:
Similar to the previous solutions, but more specific: replace two or more spaces with one:
>>> import re >>> s = "The fox jumped over the log." >>> re.sub('\s{2,}', ' ', s) 'The fox jumped over the log.'