CoreChallenge 14 of 34

Run-length encoding

Write encode(text) that compresses runs of repeated characters into the character followed by its count, and decode(encoded) that reverses it. Assume the input contains no digits.

Examples
encode("aaabccdddd") → "a3b1c2d4"
decode("a3b1c2d4") → "aaabccdddd"
Exercise

Run-length encoding

4 checks
def encode(text):
    ...


def decode(encoded):
    ...


print(encode("aaabccdddd"))
print(decode("a3b1c2d4"))
 
Python (loads on first run)Ctrl+Enter runs
Output
Press Run to try your code, then Check answer to grade it.