Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Antonio Ognio

By: a guest on Sep 11th, 2007  |  syntax: Python  |  size: 0.42 KB  |  hits: 169  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env python
  2.  
  3. str = "ABBBCCDDZ"
  4.  
  5. parts = []
  6. last_char = ''
  7. current_chunk = ''
  8. for i in range(len(str)):
  9.   current_char = str[i]
  10.   if (current_chunk == '') or (last_char == current_char):
  11.     current_chunk = current_chunk + current_char
  12.   else:
  13.     parts.append(current_chunk)
  14.     current_chunk = current_char
  15.   last_char = current_char
  16. if len(current_chunk)>0:
  17.   parts.append(current_chunk)
  18. print parts