Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)

by MonkOfAnotherSect (Sexton)
on Sep 13, 2007 at 04:32 UTC ( #638732=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)
in thread Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)

Gnah. No No and No.

The itertools version is quite lovely, but if you must do an iterative version please at least make it idiomatic. If you really needed an index, you could at least use enumerate() ;-P

mystr = "ABBBCCDDZ" def get_iterparts(mystr): buf = "" for char in mystr: if not buf or buf.endswith(char): buf += char else: yield buf buf = char if buf: yield buf print list(get_iterparts(mystr)) def get_parts(mystr): parts = [] buf = "" for char in mystr: if not buf or buf.endswith(char): buf += char else: parts.append(buf) buf = char if buf: parts.append(buf) return parts print get_parts(mystr)


Comment on Re^3: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://638732]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2014-07-10 02:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (198 votes), past polls