获取列表中出现的值,并按降序进行排列

string = input().split()
dic = {}
for i in string:
    dic[i] = dic.get(i,0) + 1

dic = sorted(dic.items(), key=lambda x: x[1],reverse=True)

for key,value in dic:
    print(key,":",value)

2020-06-13

posted @ 2020-06-13 17:39  CodeYaSuo  阅读(207)  评论(0编辑  收藏  举报