SHARE
TWEET

Antonio Ognio

a guest Sep 11th, 2007 172 Never
  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
RAW Paste Data
Top