英文词频统计预备,组合数据类型练习列表与元组都是容器,是一系列的对象。

Posted lishanting

tags:

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

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

wu=\'\'\'KEVIN:
Boy,we made it now we on it.
Think about that time we grindin uh
Nothing\'s changed since that night we pieced up lullaby.
06 now add a 1 to that,
Ten years deep and we still on it.
Like we figured look who left on top the two of .
Could you imagine otherwise?
All that talk about that life we made it come alive.
No regrets or doubts!
Once we say we say we do,
Now the world behind our views,
Seeing the bigger picture man,
I knew the end it be the two.
KRIS:
Ye!
End will be the two,
You know we got the views,
I need some real reviews,
Tell me the truth what else I gotta do.
Don\'t wanna be stayin in the shadow rear mirror view.
别告诉我你想要的想做的想说的
我在乎我想要的想做的想得到的
我活着就是为了看看天有多高
Cause we got the sauce and we started from the bottom
Right about now!
I\'ll smile don\'t wanna see u cry!
Just sing me a lullaby.
I\'ll cry for u to see ur smile,
This will be my lullaby.
I\'ll smile don\'t wanna see u cry!
Just sing me a lullaby!
I\'ll cry for u to see ur smile.
This will be my lullaby.
他们说我们其实都是一样的
面对家人我们表现都是叛逆的
只有当我真正的明白
你的付出全都是为了我将来
其实我一直都想成为一个good boy
有时不敢回家是因为害怕
我们的争吵会持续蔓延
我也害怕有天看你白发苍苍
对着我微笑的脸no!
KEVIN:
Didn\'t think a chimney would get me so deep run and chasin\',
What seem to be fantasies ain\'t wasted,
Look at time fly by tick the clock counter-wise,
Now is just a moment caught picture perfect god,
Man patience u said was a virtue!
Maybe that\'s why the fire never dimmed and pursued,
Into something even God himself couldn\'t presume,
But thanks to you I stand here the dream continues.
KRIS:
I\'ll smile don\'t wanna see u cry,
Just sing me a lullaby.
I\'ll cry for u to see ur smile,
This will be my lullaby.
I\'ll smile don\'t wanna see u cry,
Just sing me a lullaby.
I\'ll cry for u to see ur smile,
This will be my lullaby.
I\'ll smile don\'t wanna see u cry,
Just sing me a lullaby.
I\'ll cry for u to see ur smile,
This will be my lullaby.
I\'ll smile don\'t wanna see u cry,Just sing me a lullaby.
I\'ll cry for u to see ur smile.
This will be my lullaby!\'\'\'
k =wu.lower()
r =k.replace(\'.\',\' \')
i =r.replace(\'!\',\' \')
s =i.replace(\'?\',\' \')
w =s.replace(\',\',\' \')
u =w.split(\' \')
print(\'cry的次数\',u.count(\'cry\'))
print(\'lullaby次数\',u.count(\'lullaby\'))

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

>>> lst=list(\'123123321\')
>>> lst
[\'1\', \'2\', \'3\', \'1\', \'2\', \'3\', \'3\', \'2\', \'1\']
>>> lst.append(\'6\')
>>> lst
[\'1\', \'2\', \'3\', \'1\', \'2\', \'3\', \'3\', \'2\', \'1\', \'6\']
>>> lst.pop(6)
\'3\'
>>> lst
[\'1\', \'2\', \'3\', \'1\', \'2\', \'3\', \'2\', \'1\', \'6\']
>>> lst.insert(1,\'6\')
>>> lst
[\'1\', \'6\', \'2\', \'3\', \'1\', \'2\', \'3\', \'2\', \'1\', \'6\']
>>> lst.pop(2)
\'2\'
>>> lst
[\'1\', \'6\', \'3\', \'1\', \'2\', \'3\', \'2\', \'1\', \'6\']
>>> lst.index(\'3\')
2
>>> lst
[\'1\', \'6\', \'3\', \'1\', \'2\', \'3\', \'2\', \'1\', \'6\']
>>> lst.count(\'1\')
3
>>> lst
[\'1\', \'6\', \'3\', \'1\', \'2\', \'3\', \'2\', \'1\', \'6\']
>>> lst.count(\'3\')
2

 

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

答:异:元组一旦被赋值,值不可以被改变,一旦改变就会出错;但是列表可以任意的更改。

            其次是他们用不同的符号表示,复制的时候,列表用方括号[],而元组用小括号()。

同:列表与元组都是容器,是一系列的对象。

以上是关于英文词频统计预备,组合数据类型练习列表与元组都是容器,是一系列的对象。的主要内容,如果未能解决你的问题,请参考以下文章

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

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

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

作业8-组合数据类型练习,英文词频统计实例上

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

组合数据类型,英文词频统计 python