首页 > 其他 > 详细

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

时间:2017-09-20 19:14:44      阅读:337      评论:0      收藏:0      [点我收藏+]

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

lyrics=‘‘‘Waking up I see that everything is okay
The first time in my life and now it‘s so great
Slowing down I look around and I am so amazed
I think about the little things that make life great
I wouldn‘t change a thing about it
This is the best feeling
This innocence is brilliant, I hope that it will stay
This moment is perfect, please don‘t go away
I need you now
And I‘ll hold on to it, don‘t you let it pass you by
I found a place so safe, not a single tear
The first time in my life and now it‘s so clear
Feel calm, I belong, I‘m so happy here
It‘s so strong and now I let myself be sincere
I wouldn‘t change a thing about it
This is the best feeling
This innocence is brilliant, I hope that it will stay
This moment is perfect, please don‘t go away
I need you now
And I‘ll hold on to it, don‘t you let it pass you by
It‘s the state of bliss you think you‘re dreaming
It‘s the happiness inside that you‘re feeling
It‘s so beautiful, it makes you wanna cry
It‘s the state of bliss you think you‘re dreaming
It‘s the happiness inside that you‘re feeling
It‘s so beautiful, it makes you wanna cry
It‘s so beautiful, it makes you wanna cry
This innocence is brilliant, it makes you wanna cry
This innocence is brilliant, please don‘t go away
‘Cause I need you now
And I‘ll hold on to it, don‘t you let it pass you by
This innocence is brilliant, it‘s so beautiful, it‘s so beautiful
This moment is perfect, please don‘t go away
I need you now, it makes me wanna cry
And I‘ll hold on to it, don‘t you let it pass you by‘‘‘
lyrics=lyrics.lower()
lyrics=lyrics.replace(,, )
print(lyrics)
words=lyrics.split( )
print(words)

运行结果为:

技术分享

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

ls=list(12134165135241335363)
for i in range (len(ls)):
    ls[i]=int(ls[i])
print(ls)
print(ls.index(3))
print(ls.count(1))
print(ls.count(3))

运行结果为:

技术分享

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

答:元组和列表基本一样,列表与元组都是容器,是一系列的对象,二者都可以包含任意类型的元素甚至可以是一个序列,还可以包含元素的顺序

但是列表可以修改列表元素,而元组不可以修改元素

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

原文:http://www.cnblogs.com/lwn-blog/p/7562874.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!