I want to count how many leading repeat characters at the beginning of a string. So far the code I wrote:
def count_characters(s, target):
counter = 0
for i in range(len(s)):
if s[i] == target:
counter += 1
else:
return counter
It works. Now I just curious if there is a simpler way to get it done in one or two lines instead of writing an extra function?