sing='''Everytime I try to fly, I fall Without my wings, I feel so small I guess I need you, baby And everytime I see you in my dreams I see your face, it's haunting me I guess I need you, baby''' s=sing.replace("..."," ") print(s) d=s.lower() print(d) c=s.split() print(c) dic={} for i in c: count = c.count(i) dic[i] = count print(dic) dictlist = list(dic.items()) dictlist.sort(key=lambda x:x[1],reverse=True) for i in dictlist: print(i)
效果如下
f = open('news.txt','r') text = f.read() f.close() print(text)