英文词频统计预备,组合数据类型练习
Posted 猪精雅0
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了英文词频统计预备,组合数据类型练习相关的知识,希望对你有一定的参考价值。
实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
s = \'\'\'As Long As You Love Me Athough loneliness has always been a friend of mine. I\'m leaving my life in your hands. People say I\'m crazy and I am blind. Risking it all in a glance. How you got me blind is still a mystery. I can\'t get you out of my head. Don\'t care what is written in your history. As long as you\'re here with me. I don\'t care who you are. Where you\'re from. What you did. As long as you love me. Who you are. Where you\'re from. Don\'t care what you did. As long as you love me. Every little thing that you\'ve said and done. Feels like it\'s deep within me. Doesn\'t really matter if you\'re on the run. It seems like we\'re meant to be. I don\'t care who you are. Where you \'re from. What you did. As long as you love me. Who you are. Where you \'re from. Don\'t care what you did. As long as you love me. As long as you love me. As long as youlove me. I\'ve tried to hide it so that no one knows. But I guess it shows. When you look in to my eyes. What you did and where you\'re coming from. I don\'t care As long as you love me,baby! I don\'t care who you are. Where you\'re from. What you did. As long as you love me. Who you are. Where you\'re from. Don\'t care what you did. As long as you love me. Who you are. Where you\'re from. What you did. As long as you love me. Who you are. Where you\'re from. As long as you love me. Who you are. As long as you love me. What you did. I don\'t care. As long as you love me. \'\'\' a = s.lower() b = a.replace(\'.\',\' \') c = b.replace(\'!\',\' \') d = c.replace(\'?\',\' \') e = d.replace(\',\',\' \') f = e.split(\' \') print(\'as出现的次数\',f.count(\'as\')) print(\'you出现的次数\',f.count(\'you\')) print(\'long出现的次数\',f.count(\'long\')) print(\'love出现的次数\',f.count(\'love\')) print(\'me出现的次数\',f.count(\'me\'))
列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
lis = [1,2,3,2,1,2,3,2] print(\'原始的lis=\',lis) lis.append(3) print(\'在末尾添加一个3:lis=\',lis) lis.insert(3,2) print(\'在下标为3的地方插入一个2,lis=\',lis) del lis[2] print(\'删除下标为2的数,lis=\',lis) lis = list(map(int, lis)) print(\'第一个3的下标为:\',lis.index(3)) print(\'1出现的次数为:\',lis.count(1)) print(\'3出现的次数为:\',lis.count(3))
简要描述列表与元组的异同。
答:列表创建后可以通过语句修改,元组创建后不可修改
以上是关于英文词频统计预备,组合数据类型练习的主要内容,如果未能解决你的问题,请参考以下文章