string=‘‘‘
Twinkle, twinkle, little star.
Twinkle, twinkle, little star, how I wonder what you are.
Up above the world so high, like a diamond in the sky.
Twinkle, twinkle, little star, how I wonder what you are.
When the blazing sun is gone, when he nothing shines upon.
The you show your little light, Twinkle, twinkle, little star
Twinkle, twinkle, little star, How I wonder what you are.
Twinkle, twinkle, little star, how I wonder what you are.
‘‘‘
#逗号和略写,.
sym=list(",.")
for i in sym:
string=string.replace(i," ")
#小写
string=string.lower()
#按空格分裂单词
str=string.split()
a1=dict()
#单词和个数存到字典中
for i in string:
a1[i]=string.count(i)
#语法词删去
pron = ["wonder", "are", "a", "up", "he", "is","so","the"]
for i in pron:
if i in a1.keys():
del a1[i]
#按value值大小排序
dictionary=sorted(a1.items(),key=lambda item:item[1],reverse=True)
#输出
for i in range(10):
print(dictionary[i])