LZW compression: Difference between revisions

m
Line 4,178:
 
=={{header|Python}}==
{{works with|Python|3.x}}
 
In this version the dicts contain mixed typed data:
<lang python>def compress(uncompressed):
Line 4,185:
# Build the dictionary.
dict_size = 256
dictionary = dict((chr(i), i) for i in xrangerange(dict_size))
# in Python 3: dictionary = {chr(i): i for i in range(dict_size)}
 
Line 4,209:
def decompress(compressed):
"""Decompress a list of output ks to a string."""
from cStringIOio import StringIO
 
# Build the dictionary.
dict_size = 256
dictionary = dict((i, chr(i)) for i in xrangerange(dict_size))
# in Python 3: dictionary = {i: chr(i) for i in range(dict_size)}
 
Anonymous user