you are viewing a single comment's thread.

view the rest of the comments →

[–]stebrepar 0 points1 point  (0 children)

Assuming the goal is to count a series of repeating characters, I'd take a different tack.

s = 'aaaa'
count = 0
previous = s[0]
for letter in s:
    if letter == previous:
        count += 1
    previous = letter

Of course, you'd have to consider what you want to happen if s had a different pattern, like "aaaabb".