码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-09-22 14:04:21      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:arm   ice   sort   访问   修改   end   can   world   操作   

1. 下载一首英文的歌词或文章,将所有大写转换为小写,,将所有其他做分隔符(,.?!)替换为空格,并统计某些单词出现的次数。

big = ‘‘‘I‘m a big big girl !
In a big big world ! 
It‘s not a big big thing if U leave me.
But I do do feel.
That I too too will miss U much.
But I do feel I will miss U much ! 
Miss U much ! 

I can see the first leaf falling.
It‘s all yellow & nice.
It‘s so very cold outside.
Like the way I‘m feeling inside.
Outside it‘s now raining.
And tears are falling from my eyes.
I have Ur arms around me ooooh like fire.
But when I open my eyes.
U‘re gone ! 

I‘m a big big girl ! 
In a big big world ! 
It‘s not a big big thing if U leave me.
But I do do feel.
That I too too will miss U much.
But I do feel I will miss U much ! 
Miss U much ! ‘‘‘
big = big.lower()
big = big.replace(,, )
big = big.replace(!, )
big = big.replace(., )
big = big.replace(?, )
words = big.split( )
print(type(words))
print(big出现的次数为:+str(words.count(big)))

 

技术分享

2.由字符串创建一个作业评分列表,做增删改查询统计遍历操作。全部改为数值型,查询第一个3分的下标1分的同学有多少个,3分的同学有多少个

 

grade
[1, 2, 3, 2, 2, 1, 5, 3, 5]
>>> grade[1]=8
>>> grade
[1, 8, 3, 2, 2, 1, 5, 3, 5]
>>> grade.insert(1,9)
>>> grade
[1, 9, 8, 3, 2, 2, 1, 5, 3, 5]
>>> grade.append(10)
>>> grade
[1, 9, 8, 3, 2, 2, 1, 5, 3, 5, 10]
>>> grade.pop()
10
>>> grade
[1, 9, 8, 3, 2, 2, 1, 5, 3, 5]
grade.index(3)
2
grade.count(1)
2
>>> grade.count(3)
2
>>> grade.sort()
grade
[1, 1, 2, 2, 2, 3, 3, 5, 5]

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

列表和元组都属于有序序列,支持使用双向索引访问其中的元素、使用内置函数len()统计元素个数、使用运算符in测试是否包含某个元素、使用count()方法统计指定元素的出现次数和index()方法获取指定元素的索引。

列表中的项目应该包括在方括号中,可以添加、删除或是搜索列表中的项目。由于可以增加或删除项目,所以列表是可变的数据类型,即这种类型是可以被改变的。

元组和列表十分类似,但是元组是不可变的。也就是说不能修改元组。

元组通过圆括号中用逗号分割的项目定义。元组通常用在使语句或用户定义的函数能够安全地采用一组值的时候,即被使用的元组的值不会改变。

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

标签:arm   ice   sort   访问   修改   end   can   world   操作   

原文地址:http://www.cnblogs.com/0020l/p/7574049.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!