string = input("输入需要的编码的字符串:")
dictionary = {chr(i):i for i in range(32, 122)}
last = 256
p = ""
result = []
for c in string:
pc = p + c
if pc in dictionary:
p = pc
else:
result.append(dictionary[p])
dictionary[pc] = last
last += 1
p = c
if p != '':
result.append(dictionary[p])
print(result)
#求压缩比
j = len(string)
k = len(result)
n = (9*k)/(8*j)
print("压缩比:",n)
python的lZW编码代码
最新推荐文章于 2021-08-05 10:29:32 发布