英文词频统计预备,组合数据类型练习
Posted 陈馨婷
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了英文词频统计预备,组合数据类型练习相关的知识,希望对你有一定的参考价值。
1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
songs=\'\'\'
I heard that your settled down
That you found a girl and you’re married now
I heard that your dreams came true
Guess she gave you things
I didn\'t give to you.
Old friend why are you so shy
It ain\'t like you to hold back
Or hide from the light
I hate to turn up out of the blue uninvited
But I couldn\'t stay away I couldn\'t fight it
I had hoped you\'d see my face and that you\'d be reminded
That for me, it isn\'t over
Never mind, I\'ll find someone like you
I wish nothing but the best for you too
Don\'t forget me I beg I\'ll remember you said
Sometimes it lasts in love
But sometimes it hurts instead
Sometimes it lasts in love
But sometimes it hurts instead
You know how the time flies
Only yesterday was the time of our lives
We were born and raised in a summer haze
Bound by the surprise of our glory days
I hate to turn up out of the blue uninvited
But I couldn\'t stay away I couldn\'t fight it
I had hoped you\'d see my face and that you\'d be reminded
That for me, it isn\'t over
Never mind, I\'ll find someone like you
I wish nothing but the best for you too
Don\'t forget me I beg I\'ll remember you said
Sometimes it lasts in love
But sometimes it hurts instead
Sometimes it lasts in love
But sometimes it hurts instead
Nothing compares no worries or cares
Regrets and mistakes they\'re memories made
Who would have known how bitter sweet
This would taste
Never mind, I\'ll find someone like you
I wish nothing but the best for you too
Don\'t forget me I beg I\'ll remember you said
Sometimes it lasts in love
But sometimes it hurts instead
Sometimes it lasts in love
But sometimes it hurts instead
Never mind, I\'ll find someone like you
I wish nothing but the best for you too
Don\'t forget me I beg I\'ll remember you said
Sometimes it lasts in love
But sometimes it hurts instead
Sometimes it lasts in love
But sometimes it hurts instead\'\'\'
songs=songs.lower()
for i in \',.\':
songs=songs.replace(i,\'\')
words=songs.split(\' \')
print(words)
print(\'someone:\',songs.count(\'someone\'))
print(\'it:\',songs.count(\'it\'))
print(\'me:\',songs.count(\'me\'))
2.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
3.简要描述列表与元组的异同。
列表是用[]表示,元组是用()表示的;列表是可变的数据类型,能增减删改;元组是不可变的数据类型,不能修改;元组与列表的用法虽然相似,但是元组一旦初始化就不能修改。
以上是关于英文词频统计预备,组合数据类型练习的主要内容,如果未能解决你的问题,请参考以下文章