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

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

时间:2017-09-20 21:59:55      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:first   art   个数   always   school   gone   com   crazy   src   

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

song=‘‘‘Ohh wooaah  
You know you love me,I know you care
You shout whenever, And I‘ll be there
You want my love, You want my heart
And we will never ever ever be apart
Are we an item? Girl quit playing
Were just friends, Or are we saying
So theres another one, Looks right in my eyes
My first love broke my heart for the first time,
And I was like
Baby, baby, baby nooo
My baby, baby, baby noo
My baby, baby, baby nooo
I thought youd always be mine mine
Baby, baby, baby nooo
My baby, baby, baby noo
My baby, baby, baby nooo
I thought youd always be mine, oh oh
For you, I would have done whatever
Another chance and we, We get together
And wanna play it cool, About loosin‘ you
I‘ll buy you anything, I buy you any ring
And i in piece , baby fix me
And you shake me til‘ you wake me from this bad dream
Im going down, down, dooown
And just can‘t believe my first love won be around
Baby, baby, baby nooo
Baby, baby, baby nooo
My baby, baby, baby noo
My baby, baby, baby nooo
I thought youd always be mine
When i was 13 i had my first love
Here was nobody to compare my baby
And nobody came between us or could ever come above
She had me goin crazy
Oh i was starstruck.
She woke me up daily dont need no starbucks
She made my heart pound
Asking for a beat when i see her in the street
And in the school on the playground
But i really wanna see her on the weekends
She knows she got me dazy
Cause she was so amazing and now my heart is breaking
But i just keep on sayin
Baby, baby, baby nooo
My baby, baby, baby noo
My baby, baby, baby nooo
I thought youd always be mine  
Now Im all gone‘‘‘
song=song.lower()
for i in ‘,.?‘:
    song=song.replace(i,‘‘)

print(song.split(‘ ‘))

print(‘baby :‘,song.count(‘baby‘))
print(‘love :‘,song.count(‘you‘))

技术分享

 

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

 biao=list(‘123542565‘)
for i in range(len(biao)):
    biao[i]=int(biao[i])
print(‘遍历为整数:‘,biao)
biao.insert(0,0)
print(‘在第0位增加一个0:‘,biao)
biao.pop(1)
print(‘取第一个数:‘,biao)
print(‘取下标为2的数:‘,biao[2])
print(‘第一个3分的下标为:‘,biao.index(3))
print(‘1分的同学有:‘,biao.count(1))
print(‘3分的同学有:‘,biao.count(3))

技术分享

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

列表中的项目应该包括在方括号中,
你可以添加、删除或是搜索列表中的项目。
由于你可以增加或删除项目,所以列表是可变的数据类型,
即这种类型是可以被改变的。

元组和列表十分类似,但是元组是不可变的.
也就是说你不能修改元组。
元组通过圆括号中用逗号分割的项目定义。
元组通常用在使语句或用户定义的函数能够安全地采用一组值的时候,
即被使用的元组的值不会改变。

 

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

标签:first   art   个数   always   school   gone   com   crazy   src   

原文地址:http://www.cnblogs.com/pys965085265/p/7565022.html

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