题解 | #字符统计#
字符统计
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)