huffman-algorithm
✨ Key features
-
Count letters
-
Tree generation
-
Dictionary generation
-
Letter frequency calculation
-
String encoding
-
String decoding
-
Tree visualisation
It works with python 3.12 or later
🔧 Installation
It should work on any python3 version after the 1.10 but it's always good to have the latest version since it will be the one I'm sure it works on :)
⚙ Using PyPi
$ pip install huffman-algorithm
📚 Usage
📕 Dictionary generation
from huffman import Huffman
dictionary = Huffman.generate_dictionary("Hello World")
# How to see the dictionary ?
print(dictionary) # Output: {'W': '000', 'd': '001', 'e': '010', 'r': '011', 'l': '10', 'o': '110', ' ': '1110', 'H': '1111'}
🌳 Tree generation
from huffman import Huffman
tree = Huffman.generate_tree("Hello World")
# How to see the tree ?
print(tree) # Output: Node(character=None, frequency=11, children=[Node(character=None, frequency=4, children=[...]])
🔢 Letter frequency calculation
from huffman import Huffman
frequencies = Huffman.get_letters_frequency("Hello World")
# How to see the encoded string ?
print(frequencies) # Output: {' ': 1, 'H': 1, 'W': 1, 'd': 1, 'e': 1, 'r': 1, 'o': 2, 'l': 3}
⚙️ String encoding
from huffman import Huffman
encoded = Huffman.encode("Hello World")
# How to see the encoded string ?
print(encoded) # Output: '11110101010110111000011001110001'
⚙️ String decoding
from huffman import Huffman
encoded = Huffman.encode("Hello World")
dictionary = Huffman.generate_dictionary("Hello World")
decoded = Huffman.decode(encoded, dictionary)
# How to see the decoded string ?
print(decoded) # Output: 'Hello World'
🍕 Contributing
All contribution are welcomed so consider looking at the source code on GitHub
🛡 License
This project is licensed under the MIT License
Metadata
Release files for huffman-algorithm 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| huffman_algorithm-1.0.1.tar.gz | 5.4 kB | Without provenance | Details for huffman_algorithm-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| huffman_algorithm-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for huffman_algorithm-1.0.1-py3-none-any.whl |
Total release size: 9.3 kB
Release files / huffman_algorithm-1.0.1.tar.gz
| Download URL | huffman_algorithm-1.0.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f87afcd0e62d0747afc4a287d0a31dd639f485f3d3fd362b46412049d411aa3
|
|
BLAKE2b-256 checksum How to use checksums |
af3c3e7222226fd959ce8440dc95ce84605f881789e9e71433b0002c053af960
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Release files / huffman_algorithm-1.0.1-py3-none-any.whl
| Download URL | huffman_algorithm-1.0.1-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f2a6165c542eef5b50a979b087c4f5a124d5c4121ce9cac1df55167dba3417e7
|
|
BLAKE2b-256 checksum How to use checksums |
bac0b28af4484544ece8b13399ca2ac51759836f825a67b4fa7bf286c6c5657b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Security for huffman-algorithm 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.