We don't bite newbies here... much 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??

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, ...)

Create A New User
Node Status?
node history
Node Type: note [id://638732]
help
Chatterbox?
 [LanX]: strict rules : the a is long in "straße" and short in "strasse" [choroba]: So the "a" is different, not the "s" ;-) [LanX]: people knowing that it's a workaround will pronounce it right [LanX]: well [LanX]: Maße and Masse are two very different words. LanX (measures/mass) [Tanktalus]: choroba: thanks, not sure why it wasn't doing that for me, but will try to figure it out. :) [LanX]: can I copy a authotification cookie from mozilla and reuse it in LWP::Useragent? [LanX]: nevermind

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2018-03-21 15:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (269 votes). Check out past polls.

Notices?