期末综合大作业:词频统计
#1 seeFile = open('see.txt', mode='r',encoding='utf-8') seeText = seeFile.read() #从文件里读出全部文本 字符串 seeFile.close() print(seeText) #2 replaceList = [',','.',"'",'/n'] for c in replaceList: seeText = seeText.replace(c,' ') #替换掉所有标点符号 seeText = seeText.replace(' ',' ') print(seeText) #3 print(seeText.split(' ')) seeList = seeText.split(' ') # 列表:出现的单词序列 #4 seeSet = set(seeList) # 集合:有哪些单词 print(seeSet) seeDict = {} # 字典: 每个单词的统计次数 for word in seeSet: seeDict[word] = seeList.count(word) print(seeDict) #5.排序 wordCountList = list(seeDict.items()) #字典没有顺序,不能排序,转换成列表进行排序 print(wordCountList) wordCountList.sort(key=lambda x:x[1],reverse=True) # 进行排序 print(wordCountList) #6.输出Top20 for i in range(20): print(wordCountList[i]) ''' #7.写入文件 seeCountFile = open('seeCount.txt', mode='utf-8') for i in range(len(wordCountList)): seeCountFile.write(str(wordCountList[i][1]+' '+wordCountList[i][0]+'\n') seeCountFile.close() '''
It's been a long day without you my friend And I'll tell you all about it when I see you again We've come a long way from where we began Oh I'll tell you all about it when I see you again When I see you again Damn who knew all the planes we flew Good things we've been through That I'll be standing right here Talking to you about another path I know we loved to hit the road and laugh But something told me that it wouldn't last Had to switch up look at things different see the bigger picture Those were the days hard work forever pays Now I see you in a better place Now I see you in a better place How could we not talk about family when family's all that we got? Everything I went through you were standing there by my side And now you gonna be with me for the last ride It's been a long day without you my friend And I'll tell you all about it when I see you again We've come a long way from where we began Oh I'll tell you all about it when I see you again When I see you again First you both go out your way And the vibe is feeling strong and what's Small turn to a friendship a friendship Turn into a bond and that bond will never Be broke and the love will never get lost Be broke and the love will never get lost And when brotherhood come first then the line Will never be crossed established it on our own When that line had to be drawn and that line is what We reach so remember me when I'm gone We reach so remember me when I'm gone How could we not talk about family when family's all that we got? Everything I went through you were standing there by my side And now you gonna be with me for the last ride Let the light guide your way hold every memory As you go and every road you take will always lead you home It's been a long day without you my friend And I'll tell you all about it when I see you again We've come a long way from where we began Oh I'll tell you all about it when I see you again When I see you again Again When I see you again see you again see you again When I see you again It s been a long day without you my friend And I ll tell you all about it when I see you again We ve come a long way from where we began Oh I ll tell you all about it when I see you again When I see you again Damn who knew all the planes we flew Good things we ve been through That I ll be standing right here Talking to you about another path I know we loved to hit the road and laugh But something told me that it wouldn t last Had to switch up look at things different see the bigger picture Those were the days hard work forever pays Now I see you in a better place Now I see you in a better place How could we not talk about family when family s all that we got? Everything I went through you were standing there by my side And now you gonna be with me for the last ride It s been a long day without you my friend And I ll tell you all about it when I see you again We ve come a long way from where we began Oh I ll tell you all about it when I see you again When I see you again First you both go out your way And the vibe is feeling strong and what s Small turn to a friendship a friendship Turn into a bond and that bond will never Be broke and the love will never get lost Be broke and the love will never get lost And when brotherhood come first then the line Will never be crossed established it on our own When that line had to be drawn and that line is what We reach so remember me when I m gone We reach so remember me when I m gone How could we not talk about family when family s all that we got? Everything I went through you were standing there by my side And now you gonna be with me for the last ride Let the light guide your way hold every memory As you go and every road you take will always lead you home It s been a long day without you my friend And I ll tell you all about it when I see you again We ve come a long way from where we began Oh I ll tell you all about it when I see you again When I see you again Again When I see you again see you again see you again When I see you again ['It', 's', 'been', 'a', 'long', 'day', 'without', 'you', 'my', 'friend\nAnd', 'I', 'll', 'tell', 'you', 'all', 'about', 'it', 'when', 'I', 'see', 'you', 'again\nWe', 've', 'come', 'a', 'long', 'way', 'from', 'where', 'we', 'began\nOh', 'I', 'll', 'tell', 'you', 'all', 'about', 'it', 'when', 'I', 'see', 'you', 'again\nWhen', 'I', 'see', 'you', 'again\nDamn', 'who', 'knew', 'all', 'the', 'planes', 'we', 'flew\nGood', 'things', 'we', 've', 'been', 'through\nThat', 'I', 'll', 'be', 'standing', 'right', 'here\nTalking', 'to', 'you', 'about', 'another', 'path\nI', 'know', 'we', 'loved', 'to', 'hit', 'the', 'road', 'and', 'laugh\nBut', 'something', 'told', 'me', 'that', 'it', 'wouldn', 't', 'last\nHad', 'to', 'switch', 'up', 'look', 'at', 'things\ndifferent', 'see', 'the', 'bigger', 'picture\nThose', 'were', 'the', 'days', 'hard', 'work', 'forever', 'pays\nNow', 'I', 'see', 'you', 'in', 'a', 'better', 'place\nNow', 'I', 'see', 'you', 'in', 'a', 'better', 'place\nHow', 'could', 'we', 'not', 'talk', 'about', 'family\nwhen', 'family', 's', 'all', 'that', 'we', 'got?\nEverything', 'I', 'went', 'through\nyou', 'were', 'standing', 'there', 'by', 'my', 'side\nAnd', 'now', 'you', 'gonna', 'be', 'with', 'me', 'for', 'the', 'last', 'ride\nIt', 's', 'been', 'a', 'long', 'day', 'without', 'you', 'my', 'friend\nAnd', 'I', 'll', 'tell', 'you', 'all', 'about', 'it', 'when', 'I', 'see', 'you', 'again\nWe', 've', 'come', 'a', 'long', 'way', 'from', 'where', 'we', 'began\nOh', 'I', 'll', 'tell', 'you', 'all', 'about', 'it', 'when', 'I', 'see', 'you', 'again\nWhen', 'I', 'see', 'you', 'again\nFirst', 'you', 'both', 'go', 'out', 'your', 'way\nAnd', 'the', 'vibe', 'is', 'feeling', 'strong', 'and', 'what', 's\nSmall', 'turn', 'to', 'a', 'friendship', 'a', 'friendship\nTurn', 'into', 'a', 'bond', 'and', 'that', 'bond', 'will', 'never\nBe', 'broke', 'and', 'the', 'love', 'will', 'never', 'get', 'lost\nBe', 'broke', 'and', 'the', 'love', 'will', 'never', 'get', 'lost\nAnd', 'when', 'brotherhood', 'come', 'first', 'then', 'the', 'line\nWill', 'never', 'be', 'crossed', 'established', 'it', 'on', 'our', 'own\nWhen', 'that', 'line', 'had', 'to', 'be', 'drawn', 'and', 'that', 'line', 'is', 'what\nWe', 'reach', 'so', 'remember', 'me', 'when', 'I', 'm', 'gone\nWe', 'reach', 'so', 'remember', 'me', 'when', 'I', 'm', 'gone\nHow', 'could', 'we', 'not', 'talk', 'about', 'family\nwhen', 'family', 's', 'all', 'that', 'we', 'got?\nEverything', 'I', 'went', 'through', 'you\nwere', 'standing', 'there', 'by', 'my', 'side\nAnd', 'now', 'you', 'gonna', 'be', 'with', 'me', 'for', 'the', 'last', 'ride\nLet', 'the', 'light', 'guide', 'your', 'way', 'hold', 'every', 'memory\nAs', 'you', 'go', 'and', 'every', 'road', 'you\ntake', 'will', 'always', 'lead', 'you', 'home\nIt', 's', 'been', 'a', 'long', 'day', 'without', 'you', 'my', 'friend\nAnd', 'I', 'll', 'tell', 'you', 'all', 'about', 'it', 'when', 'I', 'see', 'you', 'again\nWe', 've', 'come', 'a', 'long', 'way', 'from', 'where', 'we', 'began\nOh', 'I', 'll', 'tell', 'you', 'all', 'about', 'it', 'when', 'I', 'see', 'you', 'again\nWhen', 'I', 'see', 'you', 'again\nAgain\nWhen', 'I', 'see', 'you', 'again', 'see', 'you', 'again\nsee', 'you', 'again\nWhen', 'I', 'see', 'you', 'again\n'] {'will', 'bigger', 'forever', 'talk', 'strong', 'the', 'look', 'here\nTalking', 't', 'better', 'went', 'love', 'again\n', 'crossed', 'what\nWe', 'about', 'things\ndifferent', 'friend\nAnd', 'go', 'at', 'bond', 'told', 'wouldn', 'for', 'ride\nLet', 'it', 'into', 'right', 'memory\nAs', 'last', 'vibe', 've', 's\nSmall', 'hold', 'knew', 'last\nHad', 'planes', 'established', 'gonna', 'm', 'by', 'through', 'another', 'home\nIt', 'laugh\nBut', 'family', 'in', 'there', 'been', 'tell', 'flew\nGood', 'again\nDamn', 'pays\nNow', 'you', 'were', 'without', 'be', 'gone\nWe', 'day', 'picture\nThose', 'when', 'friendship\nTurn', 'then', 'again\nFirst', 'out', 'drawn', 'a', 'ride\nIt', 'began\nOh', 'where', 'hit', 'remember', 'again\nAgain\nWhen', 'every', 'lead', 'way\nAnd', 'you\nwere', 'you\ntake', 'hard', 'both', 'side\nAnd', 'now', 'never\nBe', 'line', 'broke', 'lost\nBe', 'is', 'things', 'through\nyou', 'to', 'switch', 'not', 'lost\nAnd', 'road', 'long', 'way', 'first', 'had', 'see', 'It', 'through\nThat', 'up', 'family\nwhen', 'guide', 'we', 'who', 's', 'all', 'work', 'got?\nEverything', 'on', 'your', 'feeling', 'friendship', 'place\nHow', 'brotherhood', 'light', 'and', 'could', 'reach', 'from', 'get', 'again\nWhen', 'gone\nHow', 'I', 'come', 'never', 'always', 'turn', 'path\nI', 'my', 'standing', 'know', 'line\nWill', 'again', 'our', 'days', 'll', 'with', 'again\nWe', 'so', 'that', 'own\nWhen', 'something', 'what', 'again\nsee', 'loved', 'place\nNow', 'me'} {'will': 4, 'bigger': 1, 'forever': 1, 'talk': 2, 'strong': 1, 'the': 11, 'look': 1, 'here\nTalking': 1, 't': 1, 'better': 2, 'went': 2, 'love': 2, 'again\n': 1, 'crossed': 1, 'what\nWe': 1, 'about': 9, 'things\ndifferent': 1, 'friend\nAnd': 3, 'go': 2, 'at': 1, 'bond': 2, 'told': 1, 'wouldn': 1, 'for': 2, 'ride\nLet': 1, 'it': 8, 'into': 1, 'right': 1, 'memory\nAs': 1, 'last': 2, 'vibe': 1, 've': 4, 's\nSmall': 1, 'hold': 1, 'knew': 1, 'last\nHad': 1, 'planes': 1, 'established': 1, 'gonna': 2, 'm': 2, 'by': 2, 'through': 1, 'another': 1, 'home\nIt': 1, 'laugh\nBut': 1, 'family': 2, 'in': 2, 'there': 2, 'been': 4, 'tell': 6, 'flew\nGood': 1, 'again\nDamn': 1, 'pays\nNow': 1, 'you': 30, 'were': 2, 'without': 3, 'be': 5, 'gone\nWe': 1, 'day': 3, 'picture\nThose': 1, 'when': 9, 'friendship\nTurn': 1, 'then': 1, 'again\nFirst': 1, 'out': 1, 'drawn': 1, 'a': 11, 'ride\nIt': 1, 'began\nOh': 3, 'where': 3, 'hit': 1, 'remember': 2, 'again\nAgain\nWhen': 1, 'every': 2, 'lead': 1, 'way\nAnd': 1, 'you\nwere': 1, 'you\ntake': 1, 'hard': 1, 'both': 1, 'side\nAnd': 2, 'now': 2, 'never\nBe': 1, 'line': 2, 'broke': 2, 'lost\nBe': 1, 'is': 2, 'things': 1, 'through\nyou': 1, 'to': 5, 'switch': 1, 'not': 2, 'lost\nAnd': 1, 'road': 2, 'long': 6, 'way': 4, 'first': 1, 'had': 1, 'see': 15, 'It': 1, 'through\nThat': 1, 'up': 1, 'family\nwhen': 2, 'guide': 1, 'we': 10, 'who': 1, 's': 5, 'all': 9, 'work': 1, 'got?\nEverything': 2, 'on': 1, 'your': 2, 'feeling': 1, 'friendship': 1, 'place\nHow': 1, 'brotherhood': 1, 'light': 1, 'and': 7, 'could': 2, 'reach': 2, 'from': 3, 'get': 2, 'again\nWhen': 4, 'gone\nHow': 1, 'I': 24, 'come': 4, 'never': 3, 'always': 1, 'turn': 1, 'path\nI': 1, 'my': 5, 'standing': 3, 'know': 1, 'line\nWill': 1, 'again': 1, 'our': 1, 'days': 1, 'll': 7, 'with': 2, 'again\nWe': 3, 'so': 2, 'that': 6, 'own\nWhen': 1, 'something': 1, 'what': 1, 'again\nsee': 1, 'loved': 1, 'place\nNow': 1, 'me': 5} [('will', 4), ('bigger', 1), ('forever', 1), ('talk', 2), ('strong', 1), ('the', 11), ('look', 1), ('here\nTalking', 1), ('t', 1), ('better', 2), ('went', 2), ('love', 2), ('again\n', 1), ('crossed', 1), ('what\nWe', 1), ('about', 9), ('things\ndifferent', 1), ('friend\nAnd', 3), ('go', 2), ('at', 1), ('bond', 2), ('told', 1), ('wouldn', 1), ('for', 2), ('ride\nLet', 1), ('it', 8), ('into', 1), ('right', 1), ('memory\nAs', 1), ('last', 2), ('vibe', 1), ('ve', 4), ('s\nSmall', 1), ('hold', 1), ('knew', 1), ('last\nHad', 1), ('planes', 1), ('established', 1), ('gonna', 2), ('m', 2), ('by', 2), ('through', 1), ('another', 1), ('home\nIt', 1), ('laugh\nBut', 1), ('family', 2), ('in', 2), ('there', 2), ('been', 4), ('tell', 6), ('flew\nGood', 1), ('again\nDamn', 1), ('pays\nNow', 1), ('you', 30), ('were', 2), ('without', 3), ('be', 5), ('gone\nWe', 1), ('day', 3), ('picture\nThose', 1), ('when', 9), ('friendship\nTurn', 1), ('then', 1), ('again\nFirst', 1), ('out', 1), ('drawn', 1), ('a', 11), ('ride\nIt', 1), ('began\nOh', 3), ('where', 3), ('hit', 1), ('remember', 2), ('again\nAgain\nWhen', 1), ('every', 2), ('lead', 1), ('way\nAnd', 1), ('you\nwere', 1), ('you\ntake', 1), ('hard', 1), ('both', 1), ('side\nAnd', 2), ('now', 2), ('never\nBe', 1), ('line', 2), ('broke', 2), ('lost\nBe', 1), ('is', 2), ('things', 1), ('through\nyou', 1), ('to', 5), ('switch', 1), ('not', 2), ('lost\nAnd', 1), ('road', 2), ('long', 6), ('way', 4), ('first', 1), ('had', 1), ('see', 15), ('It', 1), ('through\nThat', 1), ('up', 1), ('family\nwhen', 2), ('guide', 1), ('we', 10), ('who', 1), ('s', 5), ('all', 9), ('work', 1), ('got?\nEverything', 2), ('on', 1), ('your', 2), ('feeling', 1), ('friendship', 1), ('place\nHow', 1), ('brotherhood', 1), ('light', 1), ('and', 7), ('could', 2), ('reach', 2), ('from', 3), ('get', 2), ('again\nWhen', 4), ('gone\nHow', 1), ('I', 24), ('come', 4), ('never', 3), ('always', 1), ('turn', 1), ('path\nI', 1), ('my', 5), ('standing', 3), ('know', 1), ('line\nWill', 1), ('again', 1), ('our', 1), ('days', 1), ('ll', 7), ('with', 2), ('again\nWe', 3), ('so', 2), ('that', 6), ('own\nWhen', 1), ('something', 1), ('what', 1), ('again\nsee', 1), ('loved', 1), ('place\nNow', 1), ('me', 5)] [('you', 30), ('I', 24), ('see', 15), ('the', 11), ('a', 11), ('we', 10), ('about', 9), ('when', 9), ('all', 9), ('it', 8), ('and', 7), ('ll', 7), ('tell', 6), ('long', 6), ('that', 6), ('be', 5), ('to', 5), ('s', 5), ('my', 5), ('me', 5), ('will', 4), ('ve', 4), ('been', 4), ('way', 4), ('again\nWhen', 4), ('come', 4), ('friend\nAnd', 3), ('without', 3), ('day', 3), ('began\nOh', 3), ('where', 3), ('from', 3), ('never', 3), ('standing', 3), ('again\nWe', 3), ('talk', 2), ('better', 2), ('went', 2), ('love', 2), ('go', 2), ('bond', 2), ('for', 2), ('last', 2), ('gonna', 2), ('m', 2), ('by', 2), ('family', 2), ('in', 2), ('there', 2), ('were', 2), ('remember', 2), ('every', 2), ('side\nAnd', 2), ('now', 2), ('line', 2), ('broke', 2), ('is', 2), ('not', 2), ('road', 2), ('family\nwhen', 2), ('got?\nEverything', 2), ('your', 2), ('could', 2), ('reach', 2), ('get', 2), ('with', 2), ('so', 2), ('bigger', 1), ('forever', 1), ('strong', 1), ('look', 1), ('here\nTalking', 1), ('t', 1), ('again\n', 1), ('crossed', 1), ('what\nWe', 1), ('things\ndifferent', 1), ('at', 1), ('told', 1), ('wouldn', 1), ('ride\nLet', 1), ('into', 1), ('right', 1), ('memory\nAs', 1), ('vibe', 1), ('s\nSmall', 1), ('hold', 1), ('knew', 1), ('last\nHad', 1), ('planes', 1), ('established', 1), ('through', 1), ('another', 1), ('home\nIt', 1), ('laugh\nBut', 1), ('flew\nGood', 1), ('again\nDamn', 1), ('pays\nNow', 1), ('gone\nWe', 1), ('picture\nThose', 1), ('friendship\nTurn', 1), ('then', 1), ('again\nFirst', 1), ('out', 1), ('drawn', 1), ('ride\nIt', 1), ('hit', 1), ('again\nAgain\nWhen', 1), ('lead', 1), ('way\nAnd', 1), ('you\nwere', 1), ('you\ntake', 1), ('hard', 1), ('both', 1), ('never\nBe', 1), ('lost\nBe', 1), ('things', 1), ('through\nyou', 1), ('switch', 1), ('lost\nAnd', 1), ('first', 1), ('had', 1), ('It', 1), ('through\nThat', 1), ('up', 1), ('guide', 1), ('who', 1), ('work', 1), ('on', 1), ('feeling', 1), ('friendship', 1), ('place\nHow', 1), ('brotherhood', 1), ('light', 1), ('gone\nHow', 1), ('always', 1), ('turn', 1), ('path\nI', 1), ('know', 1), ('line\nWill', 1), ('again', 1), ('our', 1), ('days', 1), ('own\nWhen', 1), ('something', 1), ('what', 1), ('again\nsee', 1), ('loved', 1), ('place\nNow', 1)] ('you', 30) ('I', 24) ('see', 15) ('the', 11) ('a', 11) ('we', 10) ('about', 9) ('when', 9) ('all', 9) ('it', 8) ('and', 7) ('ll', 7) ('tell', 6) ('long', 6) ('that', 6) ('be', 5) ('to', 5) ('s', 5) ('my', 5) ('me', 5)