题解 | #字符统计#
字符统计
https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
s = input().strip() s2 = set(s) # 去重 c = {} # 存 i:count(i)的键值对 d = [] # 存所有的count(i) for i in s2: if s.count(i) not in c: c[i] = s.count(i) else: c[i] = s.count(i) + 1 d = c.values() e = sorted(set(d), reverse=True) # 所有的count(i)去重后倒序排列 output = '' # 获取字典c中value = count(j)的所有keys for j in e: sn = sorted([key for key, value in c.items() if value == j]) output += ''.join(sn) print(output)