Posted By

rishi_devan on 09/10/15


Tagged


Versions (?)

LZW Decompression


 / Published in: Python
 

Lempel Ziv Welch Decompression in python

  1. dictionary = {i:chr(i) for i in range(97,123)}
  2. last = 256
  3. arr = [97, 97, 98, 256, 258, 257, 259]
  4.  
  5. result = []
  6. p = arr.pop(0)
  7. result.append(dictionary[p])
  8.  
  9. for c in arr:
  10. if c in dictionary:
  11. entry = dictionary[c]
  12. result.append(entry)
  13. dictionary[last] = dictionary[p] + entry[0]
  14. last += 1
  15. p = c
  16.  
  17. print(''.join(result))

Report this snippet  

You need to login to post a comment.