I have a character (eg. "a") and I need to check a string (eg. "aaaabcd") for the number of occurances of "a" in a row (processing stops at "b" in this case and returned value is 4).
I have something like this:
def count_char(str_, ch_):
count = 0
for c in str_:
if c == ch_:
count += 1
else:
return count
So I was thinking... Is there a better/more pythonic/simplier way to do this?