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

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

时间:2017-09-22 21:18:00      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:一个   练习   组合   个数   tar   评分   speed   实例   src   

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

s=‘‘‘One night to be confused
One night to speed up truth
We had a promise made
four hands and then away
Both under influence
we had demons in
To know what to say
Mind is a razorblade
To call for hands of above
to lean on
Wouldn‘t be good enough
for me, no
One night of magic truth
The start of simple truth
One night to push and scream
and then relief
Ten days of perfect tunes
The colors red and blue
We had a promise made
we were in love
To call for hands of above
to lean on
Wouldn‘t be good enough
for me, no
To call for hands of above
to lean on
Wouldn‘t be good enough
for me, no
And you
you knew the hand of a devil
And you
kept us away with wolf teeths
sharing different heartbeats
in one night
To call for hands of above
to lean on
Wouldn‘t be good enough
for me, no
To call for hands of above
to lean on
Wouldn‘t be good enough‘‘‘
r=s.lower()
for i in ,.?!:
    r=r.replace(i, )

print(to出现的次数:+str(r.count(to)))
print(good出现的次数:+str(r.count(good)))

r=r.split( )
print(r)

技术分享

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

s=list(231112232312)
print(s)
s.append(3) 
s.pop(1)    
s.insert(1,2)
print(经过增删改之后的作业评分列表:,s)
print(第一个3分的下标:,s.index(3))
print(1分的同学个数:,s.count(1))
print(3分的同学个数:,s.count(3))

技术分享

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

列表和元组非常类似,都可以嵌套,他们最大的区别是元组一旦被赋值,值不可以被改变,一旦改变就会出错,但是列表可以任意的更改。其次的区别是他们用不同的符号表示,复制的时候,列表用方括号[],而元组用小括号()。

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

标签:一个   练习   组合   个数   tar   评分   speed   实例   src   

原文地址:http://www.cnblogs.com/wujialing/p/7576884.html

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