题解 | #字符统计#

字符统计

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

list1=list(input())
list1.sort()
list2=[]

#print(list1)   ['a', 'a', 'c', 'c', 'c', 'd', 'd', 'd']

for i in list1:
    if i not in list2: list2.append(i)
    else: continue
#print(list2)   ['a', 'c', 'd']
    
list3=[]   
for i in list2:
    list4=[]
    list4.append(i)
    list4.append(list1.count(i))
    list3.append(list4)
    
#print(list3)   [['a', 2], ['c', 3], ['d', 3]]
list3.sort(key=lambda x:x[1],reverse=True)

for i in list3:
    print(i[0],end='')
#华为od#
全部评论

相关推荐

点赞 评论 收藏
分享
10-28 17:30
已编辑
华东交通大学 Java
想进开水团喝开水:字节的hr的本职工作就是黄金矿工
秋招笔试记录
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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