There are many compression programs available for Python.
But, you can build your own.
How it works
- Find repetitive sequences of characters in a string.
- Replace it with smaller sized sequence of characters.
- Repeat until the string is compressed.
There is a module called ZLIB that can be used to compress and decompress data.
pip install zlib
Run the command above in a terminal.
Run the code below in python file.
- Importing ZLIB module.
- Turning it into bytes (putting b in front of the string).
- Compressing the data.
The length is shortened by 19 bytes.
decompress() method can be used to decompress the data.