Since this thing is on the innerwebs I suppose it should have a
[python_utils.git] / letter_compress.py
index 9b4cf194c3d97a83c68c47bd0199a65c3a6e1698..6cb6b74e87c54928a5aeb7e184114e81ff877b02 100644 (file)
@@ -1,5 +1,9 @@
 #!/usr/bin/env python3
 
+# © Copyright 2021-2022, Scott Gasch
+
+"""A simple compression helper for lowercase ascii text."""
+
 import bitstring
 
 from collect.bidict import BiDict
@@ -32,14 +36,12 @@ def compress(uncompressed: str) -> bytes:
 
     """
     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:
-                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: