248黄迎迎-词频统计

时间:2021-10-21 23:39:51
  1 1.英文歌词
  2 # -*- coding:UTF-8  -*-
  3 # -*- author:肥仔丫丫  -*-
  4 
  5 news ='''I'm a big big girl in a big big world
  6 It's not a big big thing if you leave me
  7 but I do do feel that I do do will miss you much
  8 miss you much…
  9 I can see the first leaf faalling it's all yellow and nice 
 10 It's so very cold outside like the way I'm feeling inside
 11 
 12 Outside it's now raining and tears are falling from my eyes 
 13 why did it have to happen why did all have to end
 14 
 15 I have your arms around me warm like fire
 16 but when I open my eyes 
 17 you're gone…
 18 I'm a big big girl in a big big world
 19 It's not a big big thing if you leave me
 20 but I do feel that I will miss you much
 21 miss you much…'''
 22 #去掉不需要的单词
 23 exclude={'do','i','a','s','m','that','in','to'}
 24 
 25 seq=''',./'?;:..."'''
 26 for c in seq:
 27     news =news.replace(c,' ')
 28 
 29 wordList=news.lower().split()
 30 
 31 '''方法1:利用get方法来遍历扫描'''
 32 '''
 33 word_dict={}
 34 for w in wordList:
 35     word_dict[w]=word_dict.get(w, 0)+1
 36 '''
 37 
 38 
 39 # 方法2,利用统计列表Count的方法
 40 word_dict={}
 41 #消除不要的单词
 42 wordSet=set(wordList)-exclude
 43 for w in wordSet:
 44     word_dict[w]=wordList.count(w)
 45 dictList =list(word_dict.items())
 46 dictList.sort(key=lambda x:x[1],reverse=True)
 47 for i in range(20):
 48     print (dictList[i])
 49 
 50 
 51 '''
 52 
 53 for w in word_dict:
 54     print (w, word_dict[w])
 55 '''
 56 
 57 '''方法3:'''
 58 '''
 59 word_dict={}
 60 for w in wordList:
 61     if w not in word_dict:
 62         word_dict[w]=1
 63     else:
 64         word_dict[w]=word_dict[w]+1
 65         print(w, word_dict[w])
 66 '''
 67 #print sorted(news.split())
 68 
 69 
 70 '''
 71 for w in wordList:
 72 
 73     if w not in word_dict:
 74         word_dict[w]=1
 75     else:
 76         word_dict[w]=word_dict[w]+1
 77 '''
 78 
 79 2.中文
 80 str5=''''''
 81 jieba.cut(str)
 82  for i in list(jieba.cut(str)):
 83 ...  print(i)
 84 
 85 广州
 86 商学院
 87 前身
 88  89 广东省
 90 第一所
 91 独立
 92 学院
 93 -
 94 -
 95 华南
 96 师范大学
 97 增城
 98 学院
 99 100 学院
101 由康大
102 公司
103 104 "
105 211
106 工程
107 "
108 重点
109 建设
110 大学
111 -
112 -
113 华南
114 师范大学
115 联合
116 创办
117 118 1998
119 120 121 2014
122 年经
123 教育

248黄迎迎-词频统计