Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. def compress(in_str):
  2. comp_str= ""
  3.  
  4. count=1
  5. for i in range(len(in_str)-1):
  6. if in_str[i] == in_str[i+1]:
  7. count += 1
  8. else:
  9. comp_str += in_str[i] + str(count)
  10. count= 1
  11.  
  12. comp_str += in_str[i+1] + str(count)
  13.  
  14. return comp_str
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement