when inputting a text into the definition run_length_encoder the repititive letters should be compressed for example, when aaabbac is inputted the output should be ['a','a',3,'b','b',2,'a','c'] but for my code isn't compressing.
def run_length_encoder(string):
#def compress(string):
    res = []
    count = 1
    #Add in first character
    res.append(string[0])
    #Iterate through loop, skipping last one
    for i in range(len(string)-1):
        if(string[i] == string[i+1]):
            count+=1
            res.append(string[i+1])
        else:
            if(count > 1):
                #Ignore if no repeats
                res.append(count)
            res.append(string[i+1])
            count = 1
    #print last one
    if(count > 1):
        res.append(str(count))
    return res
for example when abbbbaa is inputed,the output is supposed to be this ['a', 'b', 'b', 4, 'a', 'a', 2] instead i am getting this ['a', 'b', 'b', 'b', 'b', 4, 'a', 'a', '2']
 
     
     
     
     
    