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

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

str='''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
'''
print(str.lower())
print(str.replace(',',' '))
print(str.split(' '))
print(str.count('so'))

 

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

classmates=['3','2','2','1','2','1','3']
print(classmates[2])
classmates.append('1')
print(classmates)
classmates.insert(1,'3')
print(classmates)
print('{}'.format(classmates.index('3')))
print(classmates.count('1'))
print(classmates.count('3'))

 

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

元组一旦被赋值后,值不可以改变,而列表里的值则可以任意改变。列表用[],元组用()。

posted @ 2017-09-22 13:11  070王学竞  阅读(100)  评论(0编辑  收藏  举报