huffman python_Python huffman包_程序模块 - PyPI - Python中文网
生成哈夫曼碼本!Huffman codes是將單個符號壓縮成二進制序列的最佳方式,該二進制序列可以在不使用符號間分隔符的情況下被明確解碼(它是“prefix-free”)。
以(symbol, weight)格式提供一個2元組的iterable,生成一個huffman碼本,作為字典以{symbol: code, ...}格式返回。>>> huffman.codebook([('A', 2), ('B', 4), ('C', 1), ('D', 1))
{'A': '10', 'B': '0', 'C': '110', 'D': '111'}
如果您有一個iterable的符號,collections.Counter是一個方便的方法來對它們進行匯總。>>> 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'}
歡迎加入QQ群-->: 979659372
推薦PyPI第三方庫
總結
以上是生活随笔為你收集整理的huffman python_Python huffman包_程序模块 - PyPI - Python中文网的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机网络与通信思维导图,用思维导图描述
- 下一篇: python写选择排序_如何快速掌握py