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

本文通过具体实例展示了如何使用Python进行文本预处理,包括字符替换、大小写转换、单词计数及列表操作,同时对比了列表与元组的特性。

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

str='''I'm tired of being what you want me to be
Feeling so faithless lost under the surface
Don't know what you're expecting of me
Put under the pressure of walking in your shoes
(Caught in the undertow just caught in the undertow)
Every step I take is another mistake to you
(Caught in the undertow just caught in the undertow)
I've become so numb I can't feel you there
I've become so tired so much more aware
I've becoming this all I want to do
Is be more like me and be less like you
Can't you see that you're smothering me
Holding too tightly afraid to lose control
Cause everything that you thought I would be
Has fallen apart right in front of you
(Caught in the undertow just caught in the undertow)
Every step that I take is another mistake to you
(Caught in the undertow just caught in the undertow)
And every second I waste is more than I can take
I've become so numb I can't feel you there
I've become so tired so much more aware
I've becoming this all I want to do
Is be more like me and be less like you
And I know
I may end up failing too
But I know
You were just like me with someone disappointed in you
I've become so numb I can't feel you there
I've become so tired so much more aware
I've becoming this all I want to do
Is be more like me and be less like you
I've become so numb I can't feel you there
Is everything what you want me to be
I've become so numb I can't feel you there
Is everything what you want me to be
'''
print(str.lower())
print(str.replace(',',' '))
print(str.split(' '))
print(str.count('so'))

 

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

classmates=['3','2','2','1','2','1','3']
print(classmates[2])
classmates.append('1')
print(classmates)
classmates.insert(1,'3')
print(classmates)
print('{}'.format(classmates.index('3')))
print(classmates.count('1'))
print(classmates.count('3'))

 

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

元组一旦被赋值后,值不可以改变,而列表里的值则可以任意改变。列表用[],元组用()。

转载于:https://www.cnblogs.com/kebibrany/p/7573926.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值