英文词频统计预备,组合数据类型练习
1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
s='''I'm a big big girl !
In a big big world !
It's not a big big thing if you leave me.
But I do do feel.
That I too too will miss you much.
Miss you much !
I can see the first leaf falling.
It's all yellow and nice.
It's so very cold outside.
Like the way I'm feeling inside.
I'm a big big girl !
In a big big world !
It's not a big big thing if you leave me.
But I do do feel.
That I too too will miss you much.
Miss you much !
Outside it's now raining.
And tears are falling from my eyes.
Why did it have to happen ?
Why did it all have to end ?
I'm a big big girl !
In a big big world !
It's not a big big thing if you leave me.
But I do do feel.
That I too too will miss you much.
Miss you much !
I have your arms around me warm like fire.
But when I open my eyes.
You're gone !
I'm a big big girl !
In a big big world !
It's not a big big thing if you leave me.
But I do do feel.
That I too too will miss you much.
Miss you much !
I'm a big big girl !
In a big big world !
It's not a big big thing if you leave me.
But I do feel that will miss you much !
Miss you much ! '''
s=s.lower()
s=s.replace('.',' ')
s=s.replace('!',' ')
s=s.split(' ')
print(s)
print('I出现的次数:',d.count('I'))
print('big出现的次数:',d.count('big'))
2. 列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
s=list('345665435643786543')
print(s)
print("3分的人数:",s.count('3'))
print("5分的人数:",s.count('5'))
s.append('8')
print('增加一个同学的成绩为8:',s)
print('修改下标为6的同学的分数为7:',s)
3,简要描述列表与元组的异同
答:列表list是处理一组有序项目的数据结构,可以在一个列表中存储一个序列的项目。元组和列表十分相似,不过元组是不可变的,即不能修改元组,元组通过圆括号中用逗号分隔的项目定义。