题解 | #字符统计# 字典多重排序

字符统计

https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0

s=input()
s1=set(s)
#print(s1)
res={}
for i in s1:
    n=s.count(i)
    res[i]=n
res1=sorted(res.items(),key=lambda x:(x[1],-ord(x[0])),reverse=True)
#print(res1)
print(''.join([i[0] for i in res1]))

字典多重排序:res1=sorted(res.items(),key=lambda x:(x[1],-ord(x[0])),reverse=True) 输出结果为列表

全部评论

相关推荐

点赞 评论 收藏
分享
缒梦&独舞:这家公司是这样的,去年给我实习offer了,不过也是面着玩儿的,他周六还要去做公益志愿活动
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-11 13:34
offe从四面八方来:我真的没时间陪你闹了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务