Self-paced

Explore our extensive collection of courses designed to help you master various subjects and skills. Whether you're a beginner or an advanced learner, there's something here for everyone.

Bootcamp

Learn live

Join us for our free workshops, webinars, and other events to learn more about our programs and get started on your journey to becoming a developer.

Upcoming live events

Learning library

For all the self-taught geeks out there, here is our content library with most of the learning materials we have produced throughout the years.

It makes sense to start learning by reading and watching videos about fundamentals and how things work.

Search from all Lessons


LoginGet Started

Register to 4Geeks

← Back to Projects

Compression Algorithm w/Python

Difficulty

  • easy

Average duration

4 hrs

Technologies

Difficulty

  • easy

Average duration

4 hrs

πŸ“ Instructions

Lets create a compression algorithm 🀯 It sounds hard but it's something achievable for almost anyone.

πŸ“ Instructions

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:

NameDescription
compress.pyContains the algorithm to compress the content, it has a function "compress" that receives the raw text and returns the compressed version of it
decompress.pyIt'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.pyThis is entry file, and there is no need to update it, it imports and uses the other two files

πŸ”’ Steps

  1. Take time to understand the code, start by opening and reading the 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.
  2. Run the app.py by typing python3 app.py and undestand what is the output and why.
  3. Edit the compress.py to create the compression algorithm.
  4. Test your compression algorithm by running the app.py again.
  5. Edit the decompress.py to create the decompression algorithm.
  6. Test your decompression algorithm by running the app.py again.

🌱 How to start this project

This project comes with the necessary files to start working, but you have two options to start:

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.

🎯 Metrics

  1. Compression power: Ratio is defined as the ratio between the uncompressed size and compressed size.
  2. No Data lost: If we compress and decompress document.txt the result should be the original string of content.

🍩🍬🍭 Feeling confident?

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.

Signup and get access to similar projects

We will use it to give you access to your account.
Already have an account? Login here.

By signing up, you agree to the Terms and conditions and Privacy policy.

Difficulty

  • easy

Average duration

4 hrs

Difficulty

  • easy

Average duration

4 hrs

Difficulty

  • easy

Average duration

4 hrs

Difficulty

  • easy

Average duration

4 hrs

Signup and get access to similar projects

We will use it to give you access to your account.
Already have an account? Login here.

By signing up, you agree to the Terms and conditions and Privacy policy.

Difficulty

  • easy

Average duration

4 hrs

Difficulty

  • easy

Average duration

4 hrs