I'm trying to change the RLE compress algorithm in python 3. I want the input to be bytes instead of string. The code works with string but it does not compress bytes.
Here is the code:
def encode(data) -> bytes:
encoding = ''
prev_byte = ''
count = 1
if not data: return ''
for bytes in data:
if bytes != prev_byte:
if prev_byte:
encoding += str(count) + prev_byte
count = 1
prev_byte = bytes
else:
count += 1
else:
encoding += str(count) + prev_byte
return encoding
encoded = encode('AAAABBBCC')
print(encoded)
The Output is: 4A3B2C I need the input AAAABBBCC in bytes and also the output in bytes.