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

英文词频统计预备,组合数据类型练习

时间:2017-09-20 23:19:03      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:who   词频统计   评分   英文   over   mes   egret   增删改查   instead   

1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。

songs=‘‘‘
I heard that your settled down
That you found a girl and you’re married now
I heard that your dreams came true
Guess she gave you things
I didn‘t give to you.   
Old friend why are you so shy
It ain‘t like you to hold back
Or hide from the light

I hate to turn up out of the blue uninvited
But I couldn‘t stay away I couldn‘t fight it
I had hoped you‘d see my face and that you‘d be reminded
That for me, it isn‘t over

Never mind, I‘ll find someone like you
I wish nothing but the best for you too
Don‘t forget me I beg I‘ll remember you said
Sometimes it lasts in love
But sometimes it hurts instead
Sometimes it lasts in love
But sometimes it hurts instead

You know how the time flies
Only yesterday was the time of our lives
We were born and raised in a summer haze 
Bound by the surprise of our glory days

I hate to turn up out of the blue uninvited
But I couldn‘t stay away I couldn‘t fight it
I had hoped you‘d see my face and that you‘d be reminded
That for me, it isn‘t over

Never mind, I‘ll find someone like you
I wish nothing but the best for you too
Don‘t forget me I beg I‘ll remember you said
Sometimes it lasts in love
But sometimes it hurts instead
Sometimes it lasts in love
But sometimes it hurts instead

Nothing compares no worries or cares
Regrets and mistakes they‘re memories made
Who would have known how bitter sweet
This would taste 

Never mind, I‘ll find someone like you
I wish nothing but the best for you too
Don‘t forget me I beg I‘ll remember you said
Sometimes it lasts in love
But sometimes it hurts instead
Sometimes it lasts in love
But sometimes it hurts instead

Never mind, I‘ll find someone like you
I wish nothing but the best for you too
Don‘t forget me I beg I‘ll remember you said
Sometimes it lasts in love
But sometimes it hurts instead
Sometimes it lasts in love
But sometimes it hurts instead‘‘‘
songs=songs.lower()
for i in ‘,.‘:
songs=songs.replace(i,‘‘)
words=songs.split(‘ ‘)
print(words)
print(‘someone:‘,songs.count(‘someone‘))
print(‘it:‘,songs.count(‘it‘))
print(‘me:‘,songs.count(‘me‘))

技术分享

2.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。

技术分享

3.简要描述列表与元组的异同。

列表是用[]表示,元组是用()表示的;列表是可变的数据类型,能增减删改;元组是不可变的数据类型,不能修改;元组与列表的用法虽然相似,但是元组一旦初始化就不能修改。

英文词频统计预备,组合数据类型练习

标签:who   词频统计   评分   英文   over   mes   egret   增删改查   instead   

原文地址:http://www.cnblogs.com/qingting/p/7562063.html

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