Guest User

Untitled

a guest
Dec 13th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. strT1 = str(indexT) + listStr[i + 1]
  2.  
  3. '''
  4. Ziv Encoding
  5. '''
  6. str = "madma"
  7. listStr = [] # для строки сообщения
  8. listEn = []# для закодированного сообщения
  9. for i in str:
  10. listStr.append(i)
  11. #print(listStr)
  12. i = 0
  13. while(i < len(listStr)):
  14. if (i == 0):
  15. strT = ""# string to build a element of listEn
  16. strT = strT + "0" + listStr[i]
  17. listEn.append(strT)
  18. del strT
  19.  
  20. j = 0
  21. while(j < len(listEn)):
  22. for k in range (0, len(listEn)):
  23. strT = ""
  24. strT = listEn[k]
  25. if (listStr[i] == strT[1:]):
  26. indexT = i + 1 # rememer the index of element to build the element of listEn
  27. strT1 = ""
  28. strT1 = str(indexT) + listStr[i + 1]
  29. listEn.append(strT1)
  30. del indexT
  31. del strT
  32. del strT1
  33. continue
  34. else:
  35. strT = ""# string to build a element of listEn
  36. strT = strT + "0" + listStr[i]
  37. listEn.append(strT)
  38. del strT
  39.  
  40. j += 1
  41. i += 1
  42. print(listEn)
  43.  
  44. str = "madma"
Add Comment
Please, Sign In to add comment