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

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

时间:2017-09-20 23:14:26      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:turned   一个   ace   类型   hold   安全   逗号   嵌套   删除   

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

zx=‘‘‘I don‘t want nobody to get killed
I‘ll come and get you I am always ready to fight
So don‘t take all of the blame
We are all as bad
Ah wait don‘t take all of it way
You always do
We will always be something you can not control
We will overcome your salvation has begun
No signs no lights
Such a mess over all
Don‘t kill your hopes
You make me realize who I need
I‘ll be there hold on
But it changes somehow
So where are you now?
I‘ll reach you by dawn
Before you can be turned
Illusions are torn
The fallen angels you run with don‘t know
It is our pain that makes us all human after all
Warm old sepia photographs show
Our fragile precious world
Must protect it respond to the call ‘‘‘
zx=zx.lower()
for i in ‘,‘:
zx=zx.replace(i,‘ ‘)
print(zx)
words=zx.split(‘ ‘)
print(words)

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

grades=list(‘12313561325‘)
for i in range(len(grades)):
grades[i]=int(grades[i])
print(grades)
print(grades.index(3))
print(grades.count(1))
print(grades.count(3))

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

列表中的项目应该包括在方括号中,这样python就知道你是在指明一个列表。一旦你创建了一个列表,你就可以添加,删除,或者是搜索列表中的项目。由于你可以增加或删除项目,我们说列表是可变的数据类型,即这种类型是可以被改变的。
列表是可以嵌套的。
元组
元祖和列表十分相似,不过元组是不可变的。即你不能修改元组。元组通过圆括号中用逗号分隔的项目定义。
元组通常用在使语句或用户定义的函数能够安全的采用一组值的时候,即被使用的元组的值不会改变。元组可以嵌套。

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

标签:turned   一个   ace   类型   hold   安全   逗号   嵌套   删除   

原文地址:http://www.cnblogs.com/lzp963/p/7565244.html

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