首页 > 其他 > 详细

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

时间:2017-09-20 20:31:03      阅读:267      评论:0      收藏:0      [点我收藏+]

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

str=‘‘‘However,Xi wants more effort to be taken to build a safer China.
The authorities involved should be aware of the difficulties and challenges,
carefully analyze the current situation of Chinese society,
adopt technological innovation methods and improve the capacity to forecast
and prevent risks, he said.
"I‘m excited and inspired after listening to the president‘s remarks,
which made a comprehensive summary of social
governance in the past five years and outlined the new
requirements and tasks in the future,"
said Huang Ming, vice-minister of public security.‘‘‘
str=str.lower()
for i in ‘,._"‘:
str=str.replace(i,‘ ‘)
words=str.split(‘ ‘)
print(words)

技术分享

 

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

le=list(‘1232213123313‘)
print(le)
for i in range(len(le)):
    le[i]=int(le[i])
print(le)
#排序
le.sort()
print(le)
#做增加一个两分的
le.append(‘2‘)
print(le)
#做删除第三个
le.pop(2)
print(le)
#做修改第三个
le[2]=‘3‘
print(le)
#做查询第5
print(le[4])
#计算有多少个一分的
print(le.count(1))
#计算有多少个三分的
print(le.count(3))

 

 技术分享

 

 

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

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

元组和列表十分类似,但是元组是不可变的.
也就是说你不能修改元组。
元组通过圆括号中用逗号分割的项目定义。
元组通常用在使语句或用户定义的函数能够安全地采用一组值的时候,
即被使用的元组的值不会改变。

 

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

原文:http://www.cnblogs.com/guomeiting/p/7562049.html

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