Suppose this string:
The fox jumped over the log.
Turning into:
import re s = "The fox jumped over the log." re.sub("\s\s+" , " ", s)
or
re.sub("\s\s+", " ", s)
since the space before comma is listed as a pet peeve in PEP 8, as mentioned by user Martin Thoma in the comments.