lst = "aaabbc"
ans = ""
c = 1;
for n in range(1,len(lst)):
    if lst[n] == lst[n-1]:
        c += 1
    else:
        ans += lst[n-1]+str(c)
        c = 1

ans += lst[-1] + str(c)

print(ans)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: