Created
November 10, 2020 17:12
-
-
Save akolybelnikov/913c08b71e7b557f3d856a8c8a2720bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compress(raw: str) -> bytes: | |
bArr = raw.encode('utf-8') | |
print([b for b in bArr]) | |
if len(bArr) == 1: | |
return bytes([1, bArr[0]]) | |
rList = [] | |
l = 0 | |
while l < len(bArr): | |
count = 1 | |
n = l | |
while n < len(bArr) - 1 and bArr[n] == bArr[n+1]: | |
count += 1 | |
n += 1 | |
l += count | |
rList.append(bytes([count, bArr[l-1]])) | |
return b''.join(rList) | |
b = compress("abbb") | |
print(b) | |
u = compress("\N{GRINNING FACE} \N{SHAMROCK}") | |
print(u) | |
v = compress("e") | |
print(v) | |
s = compress("\N{SHAMROCK}") | |
print(s) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment