组合数据类型练习,英文词频统计实例上
Posted xuejing
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了组合数据类型练习,英文词频统计实例上相关的知识,希望对你有一定的参考价值。
1、字典实例:建立学生学号成绩字典,做增删改查遍历操作。
d=[\'1\',\'2\',\'3\',\'4\',\'5\'] s=[87,91,78,90,82] g=dict(zip(d,s)) g[\'12\']=90 print(\'增加一个学生:\',g) g.pop(\'3\') print(\'删除一个学生:\',g) g[\'4\']=70 print(\'修改一个学生:\',g) print(\'查找2学生分数:\',g[\'2\']) print(\'查询字典里面没有的学生:\',g.get(\'7\',\'找不到该学生\'))
2、列表,元组,字典,集合的遍历。总计列表,元组,字典,集合的联系与区别。
d={\'001\':\'89\',\'002\':\'94\',\'003\':\'92\',\'004\':\'87\',\'005\':\'88\',\'006\':\'86\',\'007\':\'83\'} list=[\'01\',\'02\',\'03\',\'04\',\'05\',\'06\',\'07\'] tuple=(\'4\',\'2\',\'6\',\'7\',\'3\',\'7\',\'9\',) s={\'83874950\'} for i in d: print(i,d[i]) for i in list: print(i) for i in tuple: print(i) for i in s: print(i)
3、英文词频统计实例
- 待分析字符串
- 分解提取单词
- 大小写 txt.lower()
- 分隔符\'.,:;?!-_’
- 单词列表
- 单词计数字典
news=\'\'\'I\'m tired of being what you want me to be Feeling so faithless lost under the surface Don\'t know what you\'re expecting of me Put under the pressure of walking in your shoes (Caught in the undertow just caught in the undertow) Every step I take is another mistake to you (Caught in the undertow just caught in the undertow) I\'ve become so numb I can\'t feel you there I\'ve become so tired so much more aware I\'ve becoming this all I want to do Is be more like me and be less like you Can\'t you see that you\'re smothering me Holding too tightly afraid to lose control Cause everything that you thought I would be Has fallen apart right in front of you (Caught in the undertow just caught in the undertow) Every step that I take is another mistake to you (Caught in the undertow just caught in the undertow) And every second I waste is more than I can take I\'ve become so numb I can\'t feel you there I\'ve become so tired so much more aware I\'ve becoming this all I want to do Is be more like me and be less like you And I know I may end up failing too But I know You were just like me with someone disappointed in you I\'ve become so numb I can\'t feel you there I\'ve become so tired so much more aware I\'ve becoming this all I want to do Is be more like me and be less like you I\'ve become so numb I can\'t feel you there Is everything what you want me to be I\'ve become so numb I can\'t feel you there Is everything what you want me to be \'\'\' news=news.lower() print(news) for i in \',.\': news=news.replace(i,\'\') words=news.split(\' \') print(words) dic={} for i in words: dic[i]=news.count(i) news=list(dic.items()) print(\'单词计数字典:\',news,\'/n\')
以上是关于组合数据类型练习,英文词频统计实例上的主要内容,如果未能解决你的问题,请参考以下文章