Posted By


rishi_devan on 09/10/15

Tagged


Statistics


Viewed 902 times
Favorited by 0 user(s)

Related snippets


LZW Decompression


/ Published in: Python
Save to your folder(s)

Lempel Ziv Welch Decompression in python


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.