Given the following python script:
# dedupe.py
import re
def dedupe_whitespace(s,spacechars=\'\\t \'):
\"\"\"Merge repeated whitespace characters.
Examp
It's the raw heredoc string notation (r"""
) that did the trick:
# filename: dedupe.py
import re,doctest
def dedupe_whitespace(s,spacechars='\t '):
r"""Merge repeated whitespace characters.
Example:
>>> dedupe_whitespace('Black\t\tGround') #doctest: +REPORT_NDIFF
'Black\tGround'
"""
for w in spacechars:
s = re.sub(r"("+w+"+)", w, s)
return s
if __name__ == "__main__":
doctest.testmod()