Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LZW:
- @staticmethod
- def encode(s,verbose=False):
- w = ""
- result = []
- lzw_dict = {}
- for i in range(256):
- lzw_dict[chr(i)] = i
- cnt = 256
- for c in s:
- temp = w + c
- if temp in lzw_dict:
- w = temp
- else:
- result.append(lzw_dict[w])
- lzw_dict[temp] = cnt
- cnt+=1
- w = c
- result.append(lzw_dict[w])
- if verbose:
- for k,v in lzw_dict.items():
- if v > 255:
- print k,v
- return result,lzw_dict
Add Comment
Please, Sign In to add comment