lst = "aaabbc"
ans = ""
c = 1
for n in range(1, len(lst)):
if lst[n] == lst[n - 1]:
c += 1
else:
ans += str(c) + lst[n - 1]
c = 1
ans += str(c) + lst[-1]
compressed = ans
print(compressed)
decompressed = ""
num = ""
for ch in compressed:
if ch.isdigit():
num += ch
else:
decompressed += ch * int(num)
num = ""
print(decompressed)
To embed this project on your website, copy the following code and paste it into your website's HTML: