File size: 566 Bytes
1f584ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

def rmchr(text,index):
    return text[:index]+text[index+1:]

def count_rptch(text):
    maxch=(1,0)
    nowch=(0,0)
    lastch=None
    for index,i in enumerate(text):
        if lastch == i:
            nowch = (nowch[0]+1,nowch[1])
            if nowch[0]>maxch[0]:
                maxch=nowch
        else:
            nowch=(1,index)

        lastch=i

    return maxch

def remove_rptch(text,tar_len=4):
    while len(text)>tar_len:
        maxch = count_rptch(text)
        if maxch[0]<=1:
            break
        text=rmchr(text,maxch[1])
    return text