PY
py
1
2
3
4
5
6
import re
compress = lambda s: (''.join([''.join((str(len(x)), x[0])) for x in [''.join(y) if y[-1] != '' else ''.join(y[:-1]) for y in re.compile(r'(\w)(\1+)?').findall(s)]]))
print(compress('AABBCAAA'))
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run