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

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

原文地址:https://www.cnblogs.com/hany-postq473111315/p/13120968.html