实现
输入:
string='ac2at1fa3fgd2'
输出:
atacacfgdfgdfafafa
也就是string中字母后面的数字是该字母重复次数,ac 2,表示ac重复两次,排序依据是哪个数字小先排哪个字母串
from collections import Counter
string='ac2at1fa3fgd2'
num=[]
ap=[]
index=0
copy=string
di_count=0
ah_count=0
for c in list(string):
if c.isdigit():
if (index-ah_count)==index:
ap=ap
else:
ap.append(copy[index-ah_count:index])
ah_count=0
di_count+=1
else:
if (index-di_count)==index:
ap=ap
else:
num.append(copy[index-di_count:index])
di_count=0
ah_count+=1
index+=1
num.append(copy[index-di_count:index])
num_s=[]
for x in num:
t=int(x)
num_s.append(t)
C=Counter(num_s)
p=list(zip(ap,num_s))
s=sorted(p,key=lambda n:n[1])
tt=[]
for aph,num in s:
for i in range(num):
tt.append(aph)
print(''.join(tt))