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

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

SONG='''Look, if you had one shot, one opportunity
To seize everything you ever wanted…One moment
Would you capture it or just let it slip?

His palms are sweaty, knees weak, arms are heavy
There's vomit on his sweater already, mom's spaghetti
He's nervous, but on the surface he looks calm and ready
To drop bombs, but he keeps on forgettin
What he wrote down, the whole crowd goes so loud
He opens his mouth, but the words won't come out
He's chokin, how everybody's jokin now
The clock's run out, time's up over, bloah!
Snap back to reality, Oh there goes gravity
Oh, there goes Rabbit, he choked
He's so mad, but he won't give up that
Is he? No
He won't have it , he knows his whole back city's ropes'''

song=str.lower(SONG)
song=song.replace(', ',' ')
song=song.replace('!',' ')
song=song.replace('?',' ')
words=song.split(' ')
print(song)
print(words)
print(song.count('go'))

 

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

s=list('1231321321213')

#增
s.append('3')
print(s)
#删
s.pop(0)
print(s)
#改
s.insert(7,'3')
print(s)
#查询

s.index('3')
print(s)

print(s.count('3'))
print(s.count('1'))

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

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

列表可以增加删除修改,元祖不可以。

转载于:https://www.cnblogs.com/Qzlhxxx/p/7574352.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值