huffman
Generate Huffman codebooks! Huffman codes are the optimal way to compress individual symbols into a binary sequence that can be unambiguously decoded without inter-symbol separators (it is “prefix-free”).
Provided an iterable of 2-tuples in (symbol, weight) format, generate a Huffman codebook, returned as a dictionary in {symbol: code, ...} format.
>>> huffman.codebook([('A', 2), ('B', 4), ('C', 1), ('D', 1))
{'A': '10', 'B': '0', 'C': '110', 'D': '111'}
If you have an iterable of symbols, the collections.Counter is a handy way to tally them up.
>>> huffman.codebook(collections.Counter('man the stand banana man').items())
{' ': '111',
'a': '10',
'b': '0100',
'd': '0110',
'e': '11010',
'h': '0101',
'm': '1100',
'n': '00',
's': '11011',
't': '0111'}
Metadata
Release files for huffman 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| huffman-0.1.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Release files / huffman-0.1.2-py2.py3-none-any.whl
| Download URL | huffman-0.1.2-py2.py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
35234336f75b8ade2dbdd646c04d089ce79a0cc41724e02279103be864891a19
|
|
BLAKE2b-256 checksum How to use checksums |
c57299cf86630e26a02f2ee6ab649465fce7af7723635902cd79af91f6cc60e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for huffman 0.1.2
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.