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

Posted 朱茵茵

tags:

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

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

sorry=\'\'\'You gotta go and get angry at all of my honesty
You know I try but I don’t do too well with apologies
I hope I don’t run out of time, could someone call a referee?
Cause I just need one more shot at forgiveness
I know you know that I made those mistakes maybe once or twice
By once or twice I mean maybe a couple a hundred times
So let me, oh let me redeem, oh redeem, oh myself tonight
Cause I just need one more shot at second chances
[Pre-Chorus]
Yeah, is it too late now to say sorry?
Cause I’m missing more than just your body
Is it too late now to say sorry?
Yeah I know that I let you down
Is it too late to say I’m sorry now?
[Chorus]
I’m sorry, yeah
Sorry, yeah
Sorry
Yeah I know that I let you down
Is it too late to say sorry now?
[Verse 2]
I’ll take every single piece of the blame if you want me to
But you know that there is no innocent one in this game for two
I’ll go, I’ll go and then you go, you go out and spill the truth
Can we both say the words and forget this?
[Pre-Chorus]
Is it too late now to say sorry?
Cause I’m missing more than just your body
Is it too late now to say sorry?
Yeah I know that I let you down
Is it too late to say I’m sorry now?
[Bridge]
I’m not just trying to get you back on me
Cause I’m missing more than just your body
Is it too late now to say sorry?
Yeah I know that I let you down
Is it too late to say sorry now?
[Chorus]
I’m sorry, yeah
Sorry, oh
Sorry
Yeah I know that I let you down
Is it too late to say sorry now?
I’m sorry, yeah
Sorry, oh
Sorry
Yeah I know that I let you down
Is it too late to say sorry now?\'\'\'

sorry=sorry.lower()
for i in \'?,\':
sorry=sorry.replace(i,\' \')
words=sorry.split(\' \')
print(words)
print(\'sorry:\',words.count(\'sorry\'))

运行结果:

 

 

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

lb = list(\'123232123321123222333331231\')

print(lb)
for i in range(len(lb)):
    lb[i]=int(lb[i])
print(lb.index(3))
print(lb.count(1))
print(lb.count(3))

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

列表是Python的一种内置数据类型,list是一种有序的集合,可以随时添加和删除其中的元素。元组也是一种有序列表,和list非常类似,不同点是tuple一旦定义了就不可修改,在一定意义上这也提高了代码的安全性,查询方法和list一样,使用的时候能用tuple的就用tuple。列表和元组非常类似,有时候他们都干一样的事情。他们最大的区别是元组一旦被赋值,值不可以被改变,一旦改变就会出错;但是列表可以任意的更改。其次的区别是他们用不同的符号表示,复制的时候,列表用方括号[],而元组用小括号()。

 

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

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

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

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

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

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

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