首页 > 其他 > 详细

组合数据类型练习,英文词频统计实例上

时间:2017-09-26 20:24:33      阅读:290      评论:0      收藏:0      [点我收藏+]

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

#建立学生学号成绩字典
d={01:80,02:90,03:89,04:90,05:100}
print(d)

#增遍历操作
d[06]=100

#删遍历操作
d.pop(01)

#改遍历操作
d[04]=100

#查遍历操作
print(d[04])

for i in d:
    print(d)

技术分享

 

 

 

 

 

2、列表,元组,字典,集合的遍历。

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

G=list(123345237646)
for i in G:
    print(G)
    
S=tuple(abcdefghi)
for i in S:
    print(S)

d={01:70,02:90,03:100,05:79}
for i in d:
    print(d)

se=set(12435433224)
for i in se:
    print(se)

技术分享

 技术分享

技术分享

 

 

 

 

 

3、英文词频统计实例

s=‘‘‘You were the shadow to my light

Did you feel us?

Another star

You fade away

Afraid our aim is out of sight


Were you only imaginary?

Where are you now?

Atlantis

Where are you now?

Another dream

These shallow waters never met what I needed

I‘m letting go a deeper dive

Eternal silence of the sea. I‘m breathing alive

Where are you now?

Where are you now?

‘‘‘
s=s.lower()
print("全部大写转换为小写:"+s)

for i in ,!?:
    s=s.replace(i, ) 
    print(替换结果:+s)
    
s=s.split( )
print(分隔结果为:,s)

word = set(s)
dic={}
for i in word:
    dic[i]= s.count(i)
    
s=list(dic.items())
s.sort(key=lambda x:x[1],reverse=True)
print(s,\n)
print(TOP10:)
for i in range(10):
    word,count=s[i]
    print({}\t{}.format(word,count))

技术分享

技术分享

技术分享

技术分享

 

组合数据类型练习,英文词频统计实例上

原文:http://www.cnblogs.com/123hyf/p/7596014.html

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