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

Posted L文斌

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了英文词频统计预备,组合数据类型练习相关的知识,希望对你有一定的参考价值。

 

  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.答:元组和列表十分相似,元组通过圆括号中用逗号分隔的项目定义,而列表通过中括号中用逗号分隔开。

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

 

以上是关于英文词频统计预备,组合数据类型练习的主要内容,如果未能解决你的问题,请参考以下文章

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

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

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

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

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

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