result = ''.join(char * count for char, count in counts[:max_idx]
    ) + 'aa' + ''.join(char * count for char, count in counts[max_idx + 1:])
Count the number of max consecutive "a"'s from a string. Python 3