import re, doctest

def dedupe_whitespace(s, spacechars='\t '):
    """Merge repeated whitespace characters.
    Example:
    >>> dedupe_whitespace('Black\\t\\tGround')  
    'Black\\tGround'
    """
for w in spacechars:
    s = re.sub('(' + w + '+)', w, s)
return s
if __name__ == '__main__':
    doctest.testmod()
How can I include special characters (tab, newline) in a python doctest result string?