英文词频统计预备,组合数据类型练习
Posted 陆倩霞
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了英文词频统计预备,组合数据类型练习相关的知识,希望对你有一定的参考价值。
1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
lo=\'\'\'An empty street An empty house. A hole inside heart, I\'m all alone and the rooms, Are getting smaller. I wonder how I wonder why? I wonder where they are The days,we had The,songs we sang together And oh! my love I\'m,holding on forever Reaching for a love That seems so far So I say a litter prayer , No my dream will take me there. Where the skies are blue to see you once again my love Overseas from coast to coast Find a place I love the most Where the fields are green To see you once again My love! I Try to read I go to work. I\'m laughing with my friends. But I can\'t stop to keep myself From thinking I wonder how I wonder why I wonder where they are The days we had, The songs we sang togetther And oh! my love I\'mholding on forever. Reaching for a love That seems so far So,I say a litter prayer No my dream will take me there Where the skies are blue to see you once again my love Overseas from coast to coast Find a place I love the most Where the fields are green? To see you once again To hold you in my arms To promise my love To tell you from my heart You are all I\'m thinking of Reaching for a love That seems.so far So I say a litter prayer No my dream will take me there Where the skies are blue to see you once again my love Overseas from coast to coast, Find a place I love the most, Where the fields are green. To see you once again My love! And hope my dream will take me there, Where the skies are blue to see you. once again my love. Overseas from coast to coast, Find a place I love the most Where the fields are green To see you once again My love!\'\'\' s=lo.lower() s=s.replace(\',\',\' \') s=s.replace(\'.\',\' \') s=s.replace(\'?\',\' \') s=s.replace(\'!\',\' \') print(s) print(s.count(\'love\')) a=s.split(\' \') print(a)
2.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
grade=list(\'1223321232123\') print(\'作业评分列表:\\n\',grade) grade.append(\'3\') print(\'增加一个评分3:\\n\',grade) grade.pop(1) print(\'删除下标为1的评分:\\n\',grade) grade[3]=\'4\' print(\'改下标为3的评分为4:\\n\',grade) grade.insert(5,\'3\') print(\'在下标为5的评分插入评分3:\\n\',grade) number=grade.index(\'3\') print(\'第一个3分的下标为:\',number) a=grade.count(\'1\') print(\'1分的同学有:\',a,\'个\') a=grade.count(\'3\') print(\'3分的同学有:\',a,\'个\')
3.简要描述列表与元组的异同。
答:元组是不可变的。即一旦被赋值,值就不能修,元组是通过圆括号中用逗号分隔的。
列表中的元素是在方括号中,列表是可变的,创建了一个列表,可以对其进行添加,删除,查询。
以上是关于英文词频统计预备,组合数据类型练习的主要内容,如果未能解决你的问题,请参考以下文章