strx="avfff888ctgty" x=[] for s1 in strx: x.append(s1) dic=[] for x1 in x: h=0 if x1 in dic:h=100 if h<50:dic.append(x1) hasx="" for x1 in x: m=dic.index(x1) hasx=hasx+str(m) print(hasx)