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

时间:2023-02-14 17:20:05
1.实例:下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转化为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
str='''Come up to meet you, tell you I'm sorry You don't know how lovely you are 
I had to find you Tell you I need you Tell you I set you apart Tell me your secrets
Ask me your questions Oh, let's go back to the start Running in circles Coming up tales
Heads on a science apart Nobody said it was easy It's such a shame for us to part
Nobodysaid it was easyNo one ever said it would be this hard Oh, take me back to the start
I was just guessing At numbers and figures Pulling your puzzles apart Questions of science
Science and progress Do not speak as loud as my heart Tell me you love me
Come back and haunt me Oh, and I rush to the start Running in circles Chasing tales
Coming back as we are Nobody said it was easy Oh, it's such a shame for us to part Nobody
said it was easyNo one ever said it would be so hard I'm going back to the start.
'''

for i in ',.?!"':
str
=str.replace(i,' ')
print('所有分隔符替换为空格:'+str+'\n')

str
=str.lower()
print('将所有大写转换为小写:'+str+'\n')

print('you出现次数:',str.count('you'))

print('分割单词:',str.split(' '),'\n')

 



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

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

str=list('123121212123')
print('作业评分表:',str)

a
=str.index('3')
print('第一个3分的下标为:',a)

one
=str.count('1')
print('1分的同学有:',one)

three
=str.count('3')
print('3分的同学有:',three)

str.sort()
print('排序为:',str)

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

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

列表是有序序列,正向递增,反向递减,可以随时添加或删除其中元素,元组初始化就不可修改