projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Hammer on that run_tests.py thing again.
[python_utils.git]
/
letter_compress.py
diff --git
a/letter_compress.py
b/letter_compress.py
index 9b4cf194c3d97a83c68c47bd0199a65c3a6e1698..8d7c8d7259d62be5c30d19432e402eedd06bcffa 100644
(file)
--- a/
letter_compress.py
+++ b/
letter_compress.py
@@
-1,5
+1,9
@@
#!/usr/bin/env python3
#!/usr/bin/env python3
+# © Copyright 2021-2022, Scott Gasch
+
+"""A simple toy compression helper for lowercase ascii text."""
+
import bitstring
from collect.bidict import BiDict
import bitstring
from collect.bidict import BiDict
@@
-32,14
+36,12
@@
def compress(uncompressed: str) -> bytes:
"""
compressed = bitstring.BitArray()
"""
compressed = bitstring.BitArray()
- for
(n, letter) in enumerate(uncompressed)
:
+ for
letter in uncompressed
:
if 'a' <= letter <= 'z':
bits = ord(letter) - ord('a') + 1 # 1..26
else:
if letter not in special_characters:
if 'a' <= letter <= 'z':
bits = ord(letter) - ord('a') + 1 # 1..26
else:
if letter not in special_characters:
- raise Exception(
- f'"{uncompressed}" contains uncompressable char="{letter}"'
- )
+ raise Exception(f'"{uncompressed}" contains uncompressable char="{letter}"')
bits = special_characters[letter]
compressed.append(f"uint:5={bits}")
while len(compressed) % 8 != 0:
bits = special_characters[letter]
compressed.append(f"uint:5={bits}")
while len(compressed) % 8 != 0: