首页 > 其他 > 详细

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

时间:2017-09-22 20:57:22      阅读:296      评论:0      收藏:0      [点我收藏+]

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

l=‘‘‘Let it go, let it go
You‘ll never see me cry
Here I stand
And here I stay
Let the storm rage on
My power flurries through the air into the ground
My soul is spiraling in frozen fractals all around
And one thought crystallizes like an icy blast
I‘m never going back,
The past is in the past
Let it go, let it go
When I‘ll rise like the break of dawn
Let it go, let it go
That perfect girl is gone
Here I stand in the light of day
Let the storm rage on,
The cold never bothered me anyway‘‘‘
a=l.lower()
b=a.replace(,, )
c=b.replace(!, )
d=c.split( )
print(d)
print(i出现的次数:,d.count(i))
print(you出现的次数:,d.count(you))

技术分享

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

w=list(663532222)
print(分数:,w)

w.append(6)
print(增加一个6分同学:,w)

w.insert(2,2)
print(插入一个2分同学:,w)

w.pop( 3)
print(删除第三个3分同学:,w)

a=w.index(3)
print(第一个3分的下标为:,a)

b=w.count(1)
print(1分的人数为:,b)

c=w.count(3)
print(3分的人数为:,c)

e=[int(i) for i in w]
print(更改为数值型:,e)

 

技术分享

 

 

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

答:元组和列表十分相似,但是元组是不可变的,不可以进行添加、删除或修改; 列表是可变的,可以进行添加、查询或修改的操作。

 

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

原文:http://www.cnblogs.com/222ya/p/7576947.html

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