首页 > 其他 > 详细

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

时间:2017-09-22 12:49:28      阅读:229      评论:0      收藏:0      [点我收藏+]

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

g=‘‘‘Say something, I‘m giving up on you.
I‘ll be the one, if you want me to.
Anywhere, I would‘ve followed you.
Say something, I‘m giving up on you.
And I am feeling so small.
It was over my head
I know nothing at all.
And I will stumble and fall.
I‘m still learning to love
Just starting to crawl.
Say something, I‘m giving up on you.
I‘m sorry that I couldn‘t get to you.
Anywhere, I would‘ve followed you.
Say something, I‘m giving up on you.
And I will swallow my pride.
You‘re the one that I love
And I‘m saying goodbye.
Say something, I‘m giving up on you.
And I‘m sorry that I couldn‘t get to you.
And anywhere, I would have followed you.
Oh-oh-oh-oh say something, I‘m giving up on you.
Say something, I‘m giving up on you.
Say something...‘‘‘
g=g.lower()     // 小写
g=g.replace(,, )    // ,改为   
g=g.replace(., )    //.改为 
g=g.split( )       分隔
g.count(something)      统计个数
print(g)

 

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

f=list(221211322313212222132)
f.append(2)     //添加
f.pop(0)      //删除
f.insert(3,3)     // 插入
list(range(5))      //遍历
f.index(3)       //第一个3分下标
f.count(1)      //1分同学的个数
f.count(3)     //3分中学的个数

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

列表是一种有序的序列,正向递增、反向递减序号,可以随时添加和删除其中的元素。没有长度限制、元素类型可以不同。

元组与列表类似,不同之处在于元组的元素不能修改。元组使用小括号,列表使用方括号。

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

原文:http://www.cnblogs.com/misakihong/p/7574105.html

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