Q:

Count max substring of the same character

i want to write a function in which  it receives a string (s) and a single letter (s). the function needs to return the  length of the longest substring of this letter. i dont know why the function i wrote doesn't work
for exmaple: print(count_longest_repetition('eabbaaaacccaaddd', 'a') supposed to return '4'
    def count_longest_repetition(s, c):
        n= len(s)
        lst=[]
        length_charachter=0
        for i in range(n-1):
            if s[i]==c and s[i+1]==c:
                if s[i] in lst:
                    lst.append(s[i])
                    length_charachter= len(lst)
        return length_charachter

A:

Due to the condition if s[i] in lst, nothing will be appended to 'lst' as originally 'lst' is empty and the if condition will never be satisfied. Also, to traverse through the entire string you need to use range(n) as it generates numbers from 0 to n-1. This should work - 
def count_longest_repetition(s, c):
    n= len(s)
    length_charachter=0
    max_length = 0
    for i in range(n):
        if s[i] == c:
            length_charachter += 1
        else:
            length_charachter = 0
        max_length = max(max_length, length_charachter)

    return max_length

