题解 | #字符统计#

字符统计

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

from sre_compile import isstring
string=input()
strings={}
for i in string:
        if i in strings:
            strings[i]+=1
        else:
            strings[i]=1


# 根据出现次数和 ASCII 码进行排序
# 默认升序,加负号变降序
sorted_strings = sorted(strings, key=lambda x: (-strings[x], ord(x)))
sorted_string = ''.join(sorted_strings)

print(sorted_string)

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 18:13
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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