赞
踩
text = input()
text = text.lower()
# 将特殊字符替换成为空格
for ch in '!@#$%:^&*()-.;':
text = text.replace(ch, " ")
# 对字符串通过空格进行分割
words = text.split()
counts = {}
# 任务:完成对text文本的词频统计,将结果保存到counts字典中
# ********** Begin *********#
for word in words:
if word in counts:
counts[word] = counts[word]+1
else:
counts[word]=1
# ********** End **********#
items = list(counts.items())
items.sort(key=lambda x: x[1], reverse=True)
# 输出词频统计的结果
for i in range(3):
word, count = items[i]
if i<2:
print("{0}:{1}".format(word, count))
else:
print("{0}:{1}".format(word, count),end="")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。