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

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

s='''Hello, it's me
I was wondering if after all these years
You'd like to meet, to go over
Everything
They say that time's supposed to heal ya
But I ain't done much healing

Hello, can you hear me?
I'm in California dreaming about who we used to be
When we were younger and free
I've forgotten how it felt before the world fell at our feet

There's such a difference between us
And a million miles

Hello,from the other side
I must've called a thousand times to tell you
I'm sorry, for everything that I've done
But when I call you never seem to be home

Hello,from the outside
At least I can say that I've tried to tell you
I'm sorry, for breaking your heart
But it don't matter, it clearly doesn't tear you apart anymore

Hello, how are you?
It's so typical of me to talk about myself
I'm sorry, I hope that you're well
Did you ever make it out of that town
Where nothing ever happened?'''

js=s.lower()
js=js.replace(',',' ')
js=js.replace('?',' ')
print(js)
ja=js.split(' ')
print(ja)
print(js.count('hello'))

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

a=list('123321132213')

a.append('3') #增加
print(a)
a.pop(1) #删除
print(a)
a.index('3') #查询
print(a)
a.insert(2,'3') #更改
print(a)
print(a.count('2'))

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

相同:列表与元组都是容器,是一系列的对象。二者都可以包含任意类型的元素甚至可以是一个序列,还可以包含元素的顺序(不像集合和字典)

不同:列表是可变的数据类型,而元组是不可变的数据类型。

posted @ 2017-09-22 13:51  JaTae  阅读(162)  评论(0编辑  收藏  举报