Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. def span(string, char):
  2. i = 0
  3. while i < len(string) and string[i] == char:
  4. i += 1
  5. return string[0:i], string[i:]
  6.  
  7.  
  8. def count_occurrences(string):
  9. if string:
  10. print(len(span(string, string[0])[0]), string[0], sep='', end='')
  11. count_occurrences(span(string, string[0])[1])
  12. else:
  13. print()
  14.  
  15. count_occurrences('aaaaabbbbccccccaaaaaaa')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement