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

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

时间:2017-09-20 23:18:29      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:style   air   定义   this   dex   print   div   man   nbsp   

 

  1. 实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
  2. 列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
  3. 简要描述列表与元组的异同。

 

 1.答:

s=‘‘‘Beat It - Michael Jackson
They Told Him Don‘t You Ever Come Around Here
Don‘t Wanna See Your Face You Better Disappear
The Fire‘s In Their Eyes And Their Words Are Really Clear
So Beat It Just Beat It
You Better Run You Better Do What You Can
Don‘t Wanna See No Blood Don‘t Be A Macho Man
You Wanna Be Tough Better Do What You Can
So Beat It But You Wanna Be Bad
Just Beat It Beat It Beat It Beat It
No One Wants To Be Defeated
Showin‘ How Funky Strong Is Your Fighter
It Doesn‘t Matter Who‘s Wrong Or Right
Just Beat It Beat It
Just Beat It Beat It
Just Beat It Beat It Just Beat It Beat It
They‘re Out To Get You Better Leave While You Can
Don‘t Wanna Be A Boy You Wanna Be A Man
You Wanna Stay Alive Better Do What You Can
So Beat It Just Beat It
You Have To Show Them That You‘re Really Not Scared
You‘re Playin‘ With Your Life This Ain‘t No Truth Or Dare
They‘ll Kick You Then They Beat You
Then They‘ll Tell You It‘s Fair
So Beat It But You Wanna Be Bad
Just Beat It Beat It Beat It Beat It
No One Wants To Be Defeated
Showin‘ How Funky Strong Is Your Fighter
It Doesn‘t Matter Who‘s Wrong Or Right
Just Beat It Beat It Beat It Beat It
No One Wants To Be Defeated
Showin‘ How Funky Strong Is Your Fighter
It Doesn‘t Matter Who‘s Wrong Or Right
Just Beat It Beat It Beat It Beat It Beat It...
Beat It Beat It Beat It Beat It
No One Wants To Be Defeated
Showin‘ How Funky Strong Is Your Fighter
It Doesn‘t Matter Who‘s Wrong Or Right
Who Just Beat It Beat It Beat It Beat It
No One Wants To Be Defeated
Showin‘ How Funky Strong Is Your Fighter
It Doesn‘t Matter Who‘s Wrong Or Who‘s Right
Just Beat It Beat It Beat It Beat It
No One Wants To Be Defeated
Showin‘ How Funky Strong Is Your Fighter
It Doesn‘t Matter Who‘s Wrong Or Right
Just Beat It Beat It Beat It Beat It
No One Wants To Be Defeated
Showin‘ How Funky Strong Is Your Fighter
It Doesn‘t Matter Who‘s Wrong Or Right
Just Beat It
-‘‘‘
for i in ,.?!:
    s=s.replace(i, )
s=s.replace(\n, )
s=s.lower()
s=s.split( )
print(s)
print(it出现的次数,s.count(it))
print(beat出现的次数,s.count(beat))
print(no出现的次数,s.count(no))

 技术分享

 

2.答:

a=list(5201314)
for i in range(len(a)):
    a[i]=int(a[i])
print(a)
a.append(you)
a.insert(3,love)
print(a)
a.pop(3)
print(a)
print(a.index(3))
print(a.count(1))
print(a.count(3))

技术分享

 

3.答:元组和列表十分相似,元组通过圆括号中用逗号分隔的项目定义,而列表通过中括号中用逗号分隔开。

          元组不可以修改,而列表可以修改。

 

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

标签:style   air   定义   this   dex   print   div   man   nbsp   

原文地址:http://www.cnblogs.com/lwb9511/p/7562057.html

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