英文词频统计预备,组合数据类型练习
Posted 097吴嘉玲
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了英文词频统计预备,组合数据类型练习相关的知识,希望对你有一定的参考价值。
1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
s=\'\'\'One night to be confused One night to speed up truth We had a promise made four hands and then away Both under influence we had demons in To know what to say Mind is a razorblade To call for hands of above to lean on Wouldn\'t be good enough for me, no One night of magic truth The start of simple truth One night to push and scream and then relief Ten days of perfect tunes The colors red and blue We had a promise made we were in love To call for hands of above to lean on Wouldn\'t be good enough for me, no To call for hands of above to lean on Wouldn\'t be good enough for me, no And you you knew the hand of a devil And you kept us away with wolf teeths sharing different heartbeats in one night To call for hands of above to lean on Wouldn\'t be good enough for me, no To call for hands of above to lean on Wouldn\'t be good enough\'\'\' r=s.lower() for i in \',.?!\': r=r.replace(i,\' \') print(\'to出现的次数:\'+str(r.count(\'to\'))) print(\'good出现的次数:\'+str(r.count(\'good\'))) r=r.split(\' \') print(r)
2.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
s=list(\'231112232312\') print(s) s.append(\'3\') s.pop(1) s.insert(1,2) print(\'经过增删改之后的作业评分列表:\',s) print(\'第一个3分的下标:\',s.index(\'3\')) print(\'1分的同学个数:\',s.count(\'1\')) print(\'3分的同学个数:\',s.count(\'3\'))
3.简要描述列表与元组的异同。
列表和元组非常类似,都可以嵌套,他们最大的区别是元组一旦被赋值,值不可以被改变,一旦改变就会出错,但是列表可以任意的更改。其次的区别是他们用不同的符号表示,复制的时候,列表用方括号[],而元组用小括号()。
以上是关于英文词频统计预备,组合数据类型练习的主要内容,如果未能解决你的问题,请参考以下文章