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

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

时间:2017-09-22 14:11:42      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:his   images   down   weak   who   pre   实例   gravity   dex   

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

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‘))

技术分享

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

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

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

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

标签:his   images   down   weak   who   pre   实例   gravity   dex   

原文地址:http://www.cnblogs.com/Qzlhxxx/p/7574352.html

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