组合数据类型练习,英文词频统计实例上列表,元组,字典,集合的遍历。 总结列表,元组,字典,集合的联系与区别。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了组合数据类型练习,英文词频统计实例上列表,元组,字典,集合的遍历。 总结列表,元组,字典,集合的联系与区别。相关的知识,希望对你有一定的参考价值。
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)
以上是关于组合数据类型练习,英文词频统计实例上列表,元组,字典,集合的遍历。 总结列表,元组,字典,集合的联系与区别。的主要内容,如果未能解决你的问题,请参考以下文章