码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-09-22 14:12:13      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:art   空格   hold   too   code   lower   for   类型   下标   

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

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

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

标签:art   空格   hold   too   code   lower   for   类型   下标   

原文地址:http://www.cnblogs.com/kebibrany/p/7573926.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!