题解 | #字符统计#
字符统计
https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0?tpId=37&tqId=21325&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D2%26tpId%3D37%26type%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
import sys
'''
接收字符串
'''
s = list(input())
def Mycount(s):
'''
定义字典存储字符的出现次数,利用count函数统计字符出现次数
'''
dict1={}
s2 =list(set(s))
for x in s2:
dict1[x]=s.count(x)
#关键是排序函数要有2个条件,先针对值降序排序,再针对键升序排序
L =list(sorted(dict1.items(),key=lambda x:( -x[1],x[0])))
for x in L:
print(x[0],end="")
Mycount(s)
字节跳动公司福利 1297人发布