s = 'the quick brown fox jumps over the lazy dog'

def capitalize_long(match, length):
    word = match.group(0)
return word.capitalize() if len(word) > length else word
r = re.compile('\\w+')
r.sub(partial(capitalize_long, length=3), s)
Python lambda with regex