python 对字符串按字符出现次数排序,出现次数相同按字母排序

a = input()

s = sorted(set(a)) #去重以后,按字母排序

ss = sorted(s,key=lambda x:a.count(x),reverse=True)

#对s进行排序,按出现次数a.count(x),

print(''.join(ss))

python 对字符串按字符出现次数排序,出现次数相同按字母排序_第1张图片

 

你可能感兴趣的:(python,后端)