题解 | #字符统计#

字符统计

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

while True:
    try:
        s = input()
        result = {}
        for i in s:
            if i not in result:
                result[i] = s.count(i)
        output_list = sorted(result.items(), key = lambda d :(-d[1],d[0]))#这个排序的写法需要背诵,背诵起来。。。
        #注意 sorted返回的结果会把字典变成元组了,需要取通过i[0]取其键值。
        for i in output_list:
            print(i[0], end = '')
        print()
    except:
        break
全部评论

相关推荐

双尔:你就写拥有ai开发经历,熟练运用提示词,优化ai,提高ai回答质量
点赞 评论 收藏
分享
评论
点赞
2
分享

创作者周榜

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