Run-Length Encoding

easy
Unit 1 · Strings I0/3 to milestone

Run-length encoding compresses repeated characters: "aaabccdddd" → "3a1b2c4d".

Implement rle_encode(s) and rle_decode(encoded). In the encoded form, every run is a count followed by one character, and counts can have several digits ("12x"). Encoded strings never contain digits as data characters. rle_decode(rle_encode(s)) == s for any digit-free s. rle_decode raises ValueError on malformed input (a count with no character after it, or a character with no count).

#strings#compression2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Run-Length Encoding · TechGradify