Python题解 | #字符统计#

字符统计

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

import sys
from collections import Counter

while True:
    try:
        s = input()
        arr = Counter(s)
        dict1 = sorted(arr.items(), key=lambda x: x[0], reverse=False)
        dict1 = sorted(dict1, key=lambda x: x[1], reverse=True)
        
        for i in dict1:
            print(i[0], end='')


    except:
        break

全部评论
字典排序dict.items key=lambda x: x[0] reverse=False先按照key排序,生成一个list,再按照list的方式对value排序即可注意:items可以将字典转换为list,list不可以用items
点赞 回复 分享
发布于 2024-05-18 22:45 上海

相关推荐

那么好了好了:他本来公司就是做这个的,不就是正常的游戏客户端和服务器开发,软硬件联动,有啥恶心不恶心的,提前告诉你就是怕你接受不了,接受不了就没必要再往后走流程浪费时间,虽然这公司是一坨。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务