def replacement(match):
    return match.group(1).lower()
re.sub('([A-Z])\\1', replacement, 'start TT end')
Using a regular expression to replace upper case repeated letters in python with a single lowercase letter