英文词频统计预备,组合数据类型练习
- 实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
q='''Oh, Mr.Sun, Sun, Mr.Golden Sun, Please shine down on me! Oh Mr.Sun, Sun, Mr.Golden Sun, Hiding behind a tree. Little children Are asking you. Please come out so we can play with you. Oh Mr.Sun, Sun, Mr.Golden Sun, Please shine down on me!''' q=str.lower(q) q=q.replace(',',' ') q=q.replace('.',' ') q=q.replace('!',' ') t=q.count('sun')
- 列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
number=int(input('请输入分数:')) score=list('111222333123') a=str(score.index('3')) print('第一个三分位置为:'+a) print('一分同学的个数:'+str(score.count('1'))) print('三分同学的个数:'+str(score.count('3'))) #追加一个同学分数 score.append('1') print(score) #删除下标为 2 同学的分数 score.pop(2) print(score)
- 简要描述列表与元组的异同
1.元组是不可变的, 而列表是可变的。
2.元组通常由不同的数据,而列表是相同类型的数据队列。元组表示的是结构,而列表表示的是顺序。