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

Posted 09陈雨雨

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了组合数据类型练习,英文词频统计实例相关的知识,希望对你有一定的参考价值。

1.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。


score=list(\'3212233331133213\') print(\'作业评分列表:\',score) score.append(\'1\') print(\'增加:\',score) score.pop() print(\'删除:\',score) score.insert(2,\'3\') print(\'插入:\',score) score[2]=\'3\' print(\'修改:\',score) print(\'第一个3分的下标:\',score.index(\'3\')) print(\'1分的个数:\',score.count(\'1\')) print(\'3分的个数:\',score.count(\'3\'))

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

s={\'小雨\':\'1\',\'小黑\':\'3\',\'小白\':\'2\'}
print(\'查询小雨的值:\',s.get(\'小雨\'))
s.pop(\'小白\')
s[\'小李\']=\'5\'
print(\'移除小白和增加小李:\',s)
s[\'小李\']=\'6\'
print(\'修改小李:\',s)

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

a=list(\'123456789\')
b={\'小雨\':\'1\',\'小白\':\'3\',\'小黑\':\'2\'}
c=(1, 2, 3, 4, 5 )
print(\'列表的遍历为:\',end=\'\')
for i in a:
    print(i,end=\'\')
print()
print(\'元祖的遍历为:\',end=\'\')
for i in c:
    print(i,end=\'\')
print()
print(\'字典key的遍历为:\',end=\'\')
for i in b:
    print(i,end=\'\')
print()
print(\'字典value的遍历为:\',end=\'\')
for i in b.values():
    print(i,end=\'\')
print()
print(\'数组的遍历为:\',end=\'\')
for i in c:
    print(i,end=\'\')

 

 

4.英文词频统计实例

s=\'\'\'Recently, more and more students would like to go to net bars,
especially students. It has become quite commom to go there. They
waste too much precious time on playing video games in the net bar.
As a result, not only does it do harm to their health but also produces
a bad effect on their studies. Their health becomes worse and worse
and their studies are neglected. Now a lot of net bars have been shut
down in Beijing.But some students go to the net bars at suburbs to play.\'\'\'
print("do出现次数",s.count(\'do\'))
s=s.replace(",","")
s=s.replace(\'.\',\'\')
s=s.replace(\'?\',\'\')
s=s.replace(\'!\',\'\')
s=s.replace(\'\\n\',\'\')
s=s.lower()
s1=s.split(\' \')
key=set(s1)
dic={}
for i in key:
    dic[i]=s.count(i)
wc=list(dic.items())
wc.sort(key=lambda x:x[1],reverse=True)
for i in range(10):
print(wc[i])

 

以上是关于组合数据类型练习,英文词频统计实例的主要内容,如果未能解决你的问题,请参考以下文章

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

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

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

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

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

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