英文


fp=open('sing.txt','r') a=fp.read() c={'from','it','you','to','the','for','sorry'} h=a.lower() #大写换小写 for i in ',.?!': h=a.replace(i,' ')#替换成空格 words=a.split(' ')#分词,单词的列表 print(words) d={} keys=set(words)#出现过的单词的集合,字典的key keys=keys-c #print(keys) for i in keys: d[i]=words.count(i)#单词,出现次数的字典 #print(d) b=list(d.items())#列表 b.sort(key=lambda x:x[1],reverse=True)#排序 print(b) for i in range(20): print(b[i])

================== RESTART: D:/360Downloads/管理信息系统/英文歌词.py ==================
['Hello,', 'can', 'you', 'hear', "me?\nI'm", 'in', 'California', 'dreaming', 'about', 'who', 'we', 'used', 'to', 'be\nWhen', 'we', 'were', 'younger', 'and', "free\nI've", 'forgotten', 'how', 'it', 'felt', 'before', 'the', 'world', 'fell', 'at', 'our', "feet\n\nThere's", 'such', 'a', 'difference', 'between', 'us\nAnd', 'a', 'million', 'miles\n\nHello', 'from', 'the', 'other', 'side\nI', "must've", 'called', 'a', 'thousand', 'times', 'to', 'tell', "you\nI'm", 'sorry,', 'for', 'everything', 'that', "I've", 'done\nBut', 'when', 'I', 'call', 'you', 'never', 'seem', 'to', 'be', 'home\n\nHello', 'from', 'the', 'outside\nAt', 'least', 'I', 'can', 'say', 'that', "I've", 'tried', 'to', 'tell', "you\nI'm", 'sorry,', 'for', 'breaking', 'your', 'heart\nBut', 'it', "don't", 'matter,', 'it', 'clearly', "doesn't", 'tear', 'you', 'apart', 'anymore\n\nHello,', 'how', 'are', "you?\nIt's", 'so', 'typical', 'of', 'me', 'to', 'talk', 'about', "myself\nI'm", 'sorry,', 'I', 'hope', 'that', "you're", 'well\nDid', 'you', 'ever', 'make', 'it', 'out', 'of', 'that', 'town\nWhere', 'nothing', 'ever', "happened?\n\nIt's", 'no', 'secret\nThat', 'the', 'both', 'of', 'us', 'are', 'running', 'out', 'of', 'time\n\n\nHello', 'from', 'the', 'other', 'side\nI', "must've", 'called', 'a', 'thousand', 'times', 'to', 'tell', "you\nI'm", 'sorry,', 'for', 'everything', 'that', "I've", 'done\nBut', 'when', 'I', 'call', 'you', 'never', 'seem', 'to', 'be', 'home\n\nHello', 'from', 'the', 'outside\nAt', 'least', 'I', 'can', 'say', 'that', "I've", 'tried', 'to', 'tell', "you\nI'm", 'sorry,', 'for', 'breaking', 'your', 'heart\nBut', 'it', "don't", 'matter,', 'it', 'clearly', "doesn't", 'tear', 'you', 'apart', 'anymore']
[('that', 6), ('sorry,', 5), ('I', 5), ('tell', 4), ("you\nI'm", 4), ('a', 4), ("I've", 4), ('of', 4), ('can', 3), ('times', 2), ('never', 2), ("don't", 2), ('matter,', 2), ('how', 2), ('call', 2), ('other', 2), ('called', 2), ('when', 2), ('outside\nAt', 2), ('about', 2), ('out', 2), ('heart\nBut', 2), ('breaking', 2), ('tried', 2), ('apart', 2), ('thousand', 2), ('done\nBut', 2), ('are', 2), ("doesn't", 2), ('least', 2), ('tear', 2), ('say', 2), ("must've", 2), ('seem', 2), ('clearly', 2), ('we', 2), ('everything', 2), ('your', 2), ('be', 2), ('home\n\nHello', 2), ('ever', 2), ('side\nI', 2), ('make', 1), ('me', 1), ('well\nDid', 1), ('dreaming', 1), ('anymore', 1), ('at', 1), ("myself\nI'm", 1), ('secret\nThat', 1), ('so', 1), ('world', 1), ('town\nWhere', 1), ("you?\nIt's", 1), ('nothing', 1), ('who', 1), ('both', 1), ('our', 1), ('were', 1), ('between', 1), ('million', 1), ("me?\nI'm", 1), ('forgotten', 1), ('difference', 1), ('Hello,', 1), ('anymore\n\nHello,', 1), ('before', 1), ('running', 1), ('such', 1), ('California', 1), ('miles\n\nHello', 1), ('typical', 1), ('us\nAnd', 1), ('hope', 1), ('hear', 1), ('felt', 1), ('time\n\n\nHello', 1), ("free\nI've", 1), ('talk', 1), ('fell', 1), ('and', 1), ("happened?\n\nIt's", 1), ('be\nWhen', 1), ('younger', 1), ('no', 1), ('us', 1), ('in', 1), ('used', 1), ("feet\n\nThere's", 1), ("you're", 1)]
('that', 6)
('sorry,', 5)
('I', 5)
('tell', 4)
("you\nI'm", 4)
('a', 4)
("I've", 4)
('of', 4)
('can', 3)
('times', 2)
('never', 2)
("don't", 2)
('matter,', 2)
('how', 2)
('call', 2)
('other', 2)
('called', 2)
('when', 2)
('outside\nAt', 2)
('about', 2)
>>>

 

posted on 2017-09-26 10:44  张木清  阅读(133)  评论(0编辑  收藏  举报

导航