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

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.简要描述列表与元组的异同

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

 

转载于:https://www.cnblogs.com/marsk/p/7575677.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值