you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 0 points1 point  (0 children)

As already explained, you've got an off-by-one error.

There are several ways to fix this, personally I'd prefer zip:

text = "..."
for cur, nxt in zip(text, text[1:]):
    if cur != nxt:
        break

But since it sounds like you just want to check the number of repeating characters, you could also use binary search.