import re str1 = input('') str1 = str1.lower() pattern = r'[,.\s]' s_split = re.split(pattern, str1) list1 = list(filter(None, s_split)) vs=[] for index,value in enumerate(list1): number = 0 for i in vs: if i == value: number = 1 if number == 0 : vs.append(value)
for i in sorted(vs): print('%s:%s'%(i,list1.count(i)))
测试输出不对 可以参考我的代码和题干一样但是通过不了
a=input()
b=a.lower().replace(',',' ').replace('.',' ').split()
dict={}
for i in b:
dict[i]=dict.get(i,0)+1
for j in sorted(dict.items(),key=lambda x:x[0],reverse=True):
print("%s:%s"%(j[0],j[1]))