Deviopath › Python

Run-Length Encoding

Medium · Strings

Run-length encoding compresses repeated characters: each run of the same character becomes the character followed by how many times it repeats. itertools.groupby(text) groups consecutive equal characters for you, but a plain loop works too.

Write rle_encode(text) that returns the encoded string. Every run gets a count, even a run of 1. Upper and lower case are different characters. An empty string gives "".

Next: Caesar Cipher