import re
re.sub('([A-Za-z])([A-Za-z]{2,})([A-Za-z])', lambda m: '{}{}{}'.format(m.
    group(1), len(m.group(2)), m.group(3)), 'accessability, random good bye')
Replace in string based on function ouput