关于python中字符的Huffman树

2024-04-19 14:06:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我想创建一个像哈夫曼代码,但对字符后缀免费代码列表。例如:

a ~~> Word with high Frequency
.
.
.
baz ~~> Word with lower Frequency

我在python中使用这个函数来生成字符序列

def iter_all_strings():
    size = 1
    while True:
        for s in itertools.product(ascii_lowercase, repeat=size):
            yield "".join(s)
        size +=1

但它们不是无前缀的,我怎么能做到呢?你知道吗


Tags: 函数代码列表sizedefwith序列baz