CAPTCHA_recognize / utils.py
7eu7d7's picture
init
1f584ff
raw
history blame contribute delete
566 Bytes
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