Anonymous user
LZW compression: Difference between revisions
→{{header|Python}}
Line 242:
=={{header|Python}}==
In this version the dicts contain mixed typed data:
<python>
def compress(uncompressed):
"""Compress a string to a list of output symbols."""
Line 253 ⟶ 252:
w = ""
result =
for c in uncompressed:
wc = w + c
Line 278 ⟶ 277:
dictionary = dict((chr(i), chr(i)) for i in xrange(dict_size))
w = result = compressed.
for k in compressed:
if k in dictionary:
Line 285 ⟶ 284:
entry = w + w[0]
else:
raise ValueError
result += entry
|