英文词频统计预备,组合数据类型练习

1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。

lyrics=‘‘‘Waking up I see that everything is okay
The first time in my life and now it‘s so great
Slowing down I look around and I am so amazed
I think about the little things that make life great
I wouldn‘t change a thing about it
This is the best feeling
This innocence is brilliant, I hope that it will stay
This moment is perfect, please don‘t go away
I need you now
And I‘ll hold on to it, don‘t you let it pass you by
I found a place so safe, not a single tear
The first time in my life and now it‘s so clear
Feel calm, I belong, I‘m so happy here
It‘s so strong and now I let myself be sincere
I wouldn‘t change a thing about it
This is the best feeling
This innocence is brilliant, I hope that it will stay
This moment is perfect, please don‘t go away
I need you now
And I‘ll hold on to it, don‘t you let it pass you by
It‘s the state of bliss you think you‘re dreaming
It‘s the happiness inside that you‘re feeling
It‘s so beautiful, it makes you wanna cry
It‘s the state of bliss you think you‘re dreaming
It‘s the happiness inside that you‘re feeling
It‘s so beautiful, it makes you wanna cry
It‘s so beautiful, it makes you wanna cry
This innocence is brilliant, it makes you wanna cry
This innocence is brilliant, please don‘t go away
‘Cause I need you now
And I‘ll hold on to it, don‘t you let it pass you by
This innocence is brilliant, it‘s so beautiful, it‘s so beautiful
This moment is perfect, please don‘t go away
I need you now, it makes me wanna cry
And I‘ll hold on to it, don‘t you let it pass you by‘‘‘
lyrics=lyrics.lower()
lyrics=lyrics.replace(‘,‘,‘ ‘)
print(lyrics)
words=lyrics.split(‘ ‘)
print(words)

运行结果为:

2.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。

ls=list(‘12134165135241335363‘)
for i in range (len(ls)):
    ls[i]=int(ls[i])
print(ls)
print(ls.index(3))
print(ls.count(1))
print(ls.count(3))

运行结果为:

3.简要描述列表与元组的异同。

答:元组和列表基本一样,列表与元组都是容器,是一系列的对象,二者都可以包含任意类型的元素甚至可以是一个序列,还可以包含元素的顺序

但是列表可以修改列表元素,而元组不可以修改元素

时间: 2024-10-26 11:14:23

英文词频统计预备,组合数据类型练习的相关文章

英文词频统计预备 组合数据类型练习

1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词. big='''OoohOooh Put your make-up onGet your nails doneCurl your hairRun the extra mileKeep it slim so they like you, do they like you? Get your sexy onDon't be shy, girlTake it offT

作业7——英文词频统计预备,组合数据类型练习

1.实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词./ abc='''Models from different countries took to the catwalk in qipao, a traditional Chinese dress, at the first Shenyang Qipao International Cultural Festival held at the Shenyang P

英文词频统计预备,组合数据类型练习列表与元组都是容器,是一系列的对象。

实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词. wu='''KEVIN: Boy,we made it now we on it. Think about that time we grindin uh Nothing's changed since that night we pieced up lullaby. 06 now add a 1 to that, Ten years deep and we st

组合数据类型练习,英文词频统计实例上

字典实例:建立学生学号成绩字典,做增删改查遍历操作. #创建一个空字典 dict={} s=dict print(s) #增加键值对(学号-成绩) s['001']=60 s['002']=70 s['003']=80 s['004']=90 print(s) #删除 s.pop('004') print(s) #修改 s['001']=69 print(s) #查找键是否存在 s.get('005','不存在') print(s) #便历 for i in s: print(i) 2.列表,元

组合数据类型练习,英文词频统计实例

1.由字符串创建一个作业评分表,做增删改查询统计遍历操作,例如查询第一个3分的下标,统计1分的同学有几个,3分的同学有几个,增删改查等等. 2.字典实例:建立学生学号成绩字典,做增删改查遍历操作. 3.列表,元组,字典,集合的遍历. 4.英文词频统计实例 news = '''When I was young I'd listen to the radio Waiting for my favorite songs When they played I'd sing along, It make

组合数据类型和英文词频统计实例

1.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作.例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等. >>> ls=list('1231323232323131323') >>> ls ['1', '2', '3', '1', '3', '2', '3', '2', '3', '2', '3', '2', '3', '1', '3', '1', '3', '2', '3'] >>> ls.append('4'

组合数据类型练习,英文词频统计实例上列表,元组,字典,集合的遍历。 总结列表,元组,字典,集合的联系与区别。

1.字典实例:建立学生学号成绩字典,做增删改查遍历操作. d={'天':95,'青':78,'色':65,'等':66}print('学生成绩字典:',d)d['烟']=98print('增加:',d)d.pop('等')print('删除:',d)d['天']=78print('修改:',d)print('查询青成绩:',d.get('青','无')) 2.列表,元组,字典,集合的遍历.总结列表,元组,字典,集合的联系与区别. s=list('123456789')t=set('7564231

组合数据类型练习,英文词频统计实

1,建立学生学号成绩字典,做增删改查遍历操作. #创建 d={'01':73,'02':98,'03':66,'04':88,'05':73} d {'01': 73, '02': 98, '03': 66, '04': 88, '05': 73} #查找 >>> d['04'] 88 #插入 >>> d['06']='75' >>> d {'01': 73, '02': 98, '03': 66, '04': 88, '05': 73, '06':

八、组合数据类型练习,英文词频统计实例上

1.字典实例:建立学生学号成绩字典,做增删改查遍历操作. dict={'001':'66','003':'77','006':'88','009':'99'} print('学生学号成绩:',dict) dict['007']=96 print('增加学号为007的学生的成绩为96:',dict) dict.pop('001') print('删除学号为001的学生的记录:',dict) dict['007']=100 print('修改学号为007的学生的成绩为100:',dict) prin