输入为一行,由若干个单词和句号组成
输出格式参见样例。
A blockhouse is a small castle that has four openings through which to shoot.
a:2 blockhouse:1 castle:1 four:1 has:1 is:1 openings:1 shoot:1 small:1 that:1 through:1 to:1 which:1
from collections import Counter word=input().split() # 去句号 if word[-1][len(word[-1])-1] =='.': word[-1]=word[-1][0:len(word[-1])-1] # 转小写 words = [i.lower() for i in word] # 统计词频 dic = Counter(words) dic=sorted(dic.items(),key=lambda x:(x[0],x[1]),reverse=True) #for kv in dic: #print('{}:{}'.format(kv[0],kv[1])) # 反向遍历 for x in dic[::-1]: print("{}:{}".format(x[0],x[1]))