码迷,mamicode.com
首页 > 其他好文 > 详细

综合练习:词频统计

时间:2018-03-26 12:29:05      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:script   job   env   tor   ini   pycha   nts   items   most   

str_context=‘‘‘There are several reasons for this. To begin with, 
nowadays college students aim too high. All they want are “good” 
jobs which could offer good salary, comfortable working conditions, high social status among others. Consequently,
 most college students are unwilling to accept vacant jobs they consider not “good” enough.
  Another reason is that there is a big gap between the majors some students study in school and the demands of vacant jobs.
 So companies think some students are not fit for the jobs.‘‘‘

a = str_context.replace(, ).lower().split()
b = str_context.split()

str = {}
for i in b:
    count = a.count(i)
    str[i] = count

word = ‘‘‘the are is i in i‘m if what why where and my a to at‘‘‘
c = word.split()
for i in c:
    if i in str.keys():
        del (str[i])

count = sorted(str.items(),key=lambda items: items[1], reverse=True)

for i in range(10):
    print(count[i])

C:\Users\Administrator\PycharmProjects\bd\venv\Scripts\python.exe C:/Users/Administrator/PycharmProjects/bd/gzcc.py
(‘students‘, 4)
(‘for‘, 2)
(‘college‘, 2)
(‘they‘, 2)
(‘“good”‘, 2)
(‘jobs‘, 2)
(‘vacant‘, 2)
(‘not‘, 2)
(‘there‘, 2)
(‘some‘, 2)

Process finished with exit code 0

综合练习:词频统计

标签:script   job   env   tor   ini   pycha   nts   items   most   

原文地址:https://www.cnblogs.com/bin763043666/p/8649710.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!