Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def RLE(s):
- #@param s: str
- #@return str
- new_str = ''
- k = 1
- jump = 1
- lung = len(s)
- for i in range(lung):
- if i+1<lung:
- if s[i+1] == ' ':
- jump+=1
- else:
- if s[i+1] == s[i+1-jump]:
- k+=1
- else:
- if k>2:
- new_str+=str(k)+s[i+1-jump]
- k = 1
- else:
- new_str+=k*s[i+1-jump]
- k = 1
- jump = 1
- else:
- if k>2:
- new_str+=str(k)+s[i+1-jump]
- k = 1
- else:
- new_str+=k*s[i+1-jump]
- k = 1
- return new_str
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement