字符统计Python

字符统计

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

while True:
    try:
        s = input()
        c = {}  # 字典键值对存放字符及其个数
        key = []
        value = []
        res = ''
        for i in s:
            if i not in c.keys():
                c[i] = s.count(i)
        key = sorted(c.keys())  # 字符ASCII升序
        value = sorted(list(set(c.values())),reverse=True)  # 个数通过set()去除重复数后转换为列表类型降序排列
        i  = 0
        while i < len(value):
            for f in key:
                if s.count(f) ==  value[i]:
                    res += f
            i += 1
        print(res)

    except:
        break

全部评论

相关推荐

不愿透露姓名的神秘牛友
09-17 09:40
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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