+ 1
How to decompress a file and print out the rle (run length encoding) using python.
Say if a file had the text aaaaaa then you read the file and decompress it - it would print out 04a, is there a possible way on how to do that?
1 Answer
+ 12
Why 04a ?
An example of run length encoding:
from itertools import groupby
s = "aaaddd1111111000011000011111000000000kkkkkddddddd"
rle = [(c,len([*g])) for c,g in groupby(s)]
print(rle)
[('a', 3), ('d', 3), ('1', 7), ('0', 4), ('1', 2), ('0', 4), ('1', 5), ('0', 9), ('k', 5), ('d', 7)]