Lets create a compression algorithm π€― It sounds hard but it's something achievable for almost anyone.
Create an algorithm that given a string, replaces its words matching the symbols
dictionary keys and replaces them with their respective values on the same dictionary.
1symbols = { 2 "implementation": "π€―", 3 "practicality": 'π€©', 4 "better": 'π ', 5 "Although": "π₯Ί" 6}
For example:
Although, this is a great implementation of time | β should become β | π₯Ί, this is a great π€― of time |
---|
The current project has 3 main files:
Name | Description |
---|---|
compress.py | Contains the algorithm to compress the content, it has a function "compress" that receives the raw text and returns the compressed version of it |
decompress.py | It's very similar to compress.py but it contains the algorithm to convert back the content from its compressed version to the original content |
app.py | This is entry file, and there is no need to update it, it imports and uses the other two files |
app.py
and follow the algorithm with your brain, review the compress.py and decompress.py files to understand where your solution must be implemented.python3 app.py
and undestand what is the output and why.This project comes with the necessary files to start working, but you have two options to start:
a) Open this link in your browser with gitpod: https://gitpod.io#https://github.com/breatheco-de/exercise-compression-algorithm-python.git
b) You can clone this repository on your local computer:
1$ git clone https://github.com/breatheco-de/exercise-compression-algorithm-python.git
Type the following in the command line:
1python3 app.py
You should get a response similar to this:
1β No data lost. 2document.txt has 824 size, compressed.txt has 768 size, compression of 7% in 0.0003972053527832031 seconds
π‘ Important: Remember to create a new repository, update the remote (git remote set-url origin <your new url>
), and upload the code to your new repository using add
, commit
and push
.
By adding more words to the symbols
dict you can achieve more compression power.
Try to re-do the algorithm to achieve a compression power above 15% with no data lost without just adding more words.