Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Comment on


Another solution, much more verbose but certainly more readable:

#!/usr/bin/env python str = "ABBBCCDDZ" parts = [] last_char = '' current_chunk = '' for i in range(len(str)): current_char = str[i] if (current_chunk == '') or (last_char == current_char): current_chunk = current_chunk + current_char else: parts.append(current_chunk) current_chunk = current_char last_char = current_char if len(current_chunk)>0: parts.append(current_chunk) print parts

Also available here:

- Antonio Ognio, Lima-Peru


and:  <code> code here </code>

  • Please read these before you post! —
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (7)
    As of 2014-12-25 10:37 GMT
    Find Nodes?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?

      Results (160 votes), past polls