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

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

时间:2017-09-22 17:40:07      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:tar   int   sha   not   分割   遍历   running   ons   pull   

1.实例:下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转化为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
str=‘‘‘Come up to meet you, tell you I‘m sorry You don‘t know how lovely you are 
I had to find you Tell you I need you Tell you I set you apart Tell me your secrets 
Ask me your questions Oh, let‘s go back to the start Running in circles Coming up tales
Heads on a science apart  Nobody said it was easy  It‘s such a shame for us to part
Nobodysaid it was easyNo one ever said it would be this hard  Oh, take me back to the start
I was just guessing At numbers and figures Pulling your puzzles apart Questions of science
Science and progress Do not speak as loud as my heart Tell me you love me  
Come back and haunt me  Oh, and I rush to the start  Running in circles Chasing tales
Coming back as we are  Nobody said it was easy Oh, it‘s such a shame for us to part Nobody
said it was easyNo one ever said it would be so hard I‘m going back to the start.‘‘‘

for i in ,.?!":
    str=str.replace(i, )
print(所有分隔符替换为空格:+str+\n)

str=str.lower()
print(将所有大写转换为小写:+str+\n)

print(you出现次数:,str.count(you))

print(分割单词:,str.split( ),\n)

 



技术分享

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

str=list(123121212123)
print(作业评分表:,str)

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

one=str.count(1)
print(1分的同学有:,one)

three=str.count(3)
print(3分的同学有:,three)

str.sort()
print(排序为:,str)

技术分享

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

列表是有序序列,正向递增,反向递减,可以随时添加或删除其中元素,元组初始化就不可修改

 

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

标签:tar   int   sha   not   分割   遍历   running   ons   pull   

原文地址:http://www.cnblogs.com/marsk/p/7575677.html

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