首页 > 其他 > 详细

组合数据类型练习,英文词频统计实例上列表,元组,字典,集合的遍历。 总结列表,元组,字典,集合的联系与区别。

时间:2017-09-22 18:38:13      阅读:341      评论:0      收藏:0      [点我收藏+]

1.字典实例:建立学生学号成绩字典,做增删改查遍历操作。

d={‘天‘:95,‘青‘:78,‘色‘:65,‘等‘:66}
print(‘学生成绩字典:‘,d)
d[‘烟‘]=98
print(‘增加:‘,d)
d.pop(‘等‘)
print(‘删除:‘,d)
d[‘天‘]=78
print(‘修改:‘,d)
print(‘查询青成绩:‘,d.get(‘青‘,‘无‘))

技术分享

2.列表,元组,字典,集合的遍历。
总结列表,元组,字典,集合的联系与区别。

s=list(‘123456789‘)
t=set(‘756423189‘)
c={‘炊烟‘:‘1‘,‘袅袅‘:‘3‘,‘升起‘:‘2‘}
x=(1, 2, 3, 4, 5 )
print(‘列表的遍历为:‘,end=‘‘)
for i in s:
print(i,end=‘‘)
print()
print(‘元祖的遍历为:‘,end=‘‘)
for i in x:
print(i,end=‘‘)
print()
print(‘字典key的遍历为:‘,end=‘‘)
for i in c:
print(i,end=‘‘)
print()
print(‘字典value的遍历为:‘,end=‘‘)
for i in c.values():
print(i,end=‘‘)
print()
print(‘数组的遍历为:‘,end=‘‘)
for i in x:
print(i,end=‘‘)

技术分享

3. 英文词频统计实例

A.待分析字符串

B.分解提取单词

大小写 txt.lower()

分隔符‘.,:;?!-_’

单词列表

C.单词计数字典

news=‘‘‘I said excuse me little mama if I may,
Take this thought and send it your way,
And if you don‘t like that,
then send it right back,
But I just gotta say
I wanna be on you (on you),
I wanna be on you (on you)
And if you don‘t like that,
then send it right back
But I just gotta say,
I just gotta say
Hey, sh sh shawty with no limits,
that‘s what I need all the time,
I‘m wit with with it, she with it,
she not sure she put it down
Come get get get it, the business,
I hi hit it, whose is it
The Benz with the windows tinted,
oh I get dirty south
Showning, like them grown men,
goose patrongen
Let let me go in, sexy moanin,
ca catch me jonesin
Let no not ever with
this little mama off schedule
Got me achy, call me papi,
hottest I be fly as feathers
But but bout that, sh shawty housed that,
you you got that prowl cat
I wanna pop it like ecstasy,
pretty face and all thatbillion yuan (2.1 billion U.S. dollars) year on year in the first fiscal3 quarter ending June. The group‘s revenue was about 50 billion yuan in the quarter, up 56 percent year on year.‘‘‘
news=news.lower()
for i in ‘,.()‘:
news=news.replace(i,‘ ‘)
words=news.split(‘ ‘)
print(words)

技术分享

 

组合数据类型练习,英文词频统计实例上列表,元组,字典,集合的遍历。 总结列表,元组,字典,集合的联系与区别。

原文:http://www.cnblogs.com/lzp963/p/7576200.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!