组合数据类型练习,英文词频统计实例上
Posted yyjdxgz
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了组合数据类型练习,英文词频统计实例上相关的知识,希望对你有一定的参考价值。
- 字典实例:建立学生学号成绩字典,做增删改查遍历操作。
id=[\'01\',\'02\',\'03\',\'04\',\'05\',\'06\',\'07\',\'08\',\'09\',\'11\',\'19\'] score=[46,60,90,74,51,59,90,100,78,45,98] grade=dict(zip(id,score)) grade[\'12\']=90 print(\'增加一个学生:\',grade) grade.pop(\'04\') print(\'删除一个学生:\',grade) grade[\'19\']=59 print(\'修改一个学生:\',grade) print(\'查找07学生分数:\',grade[\'07\']) print(\'查询字典里面没有的学生:\',grade.get(\'15\',\'找不到该学生\'))
- 列表,元组,字典,集合的遍历。
总结列表,元组,字典,集合的联系与区别。#列表,元组,字典,集合的遍历。 #总结列表,元组,字典,集合的联系与区别。 l=[\'1\',\'2\',\'3\',\'4\',\'5\',\'9\',\'1\',\'1\',\'1\'] print(\'列表遍历:\',l) for i in l: print(i) t=tuple(\'123459111\') print(\'元组遍历:\',t) for i in t: print(i) dics={\'Tom\':1,\'Jame\':2,\'Mary\':3,\'Jack\':4,\'Anar\':5,\'Tuma\':9,\'AngleBaby\':1} print(\'字典遍历:\',dics) for i in dics: print(i,dics[i]) a=set(\'12345\') print(\'集合遍历:\',a) for i in a: print(i)
列表 元组 集合 字典 英文 list tuple set dict 可否读写 读写 只读 读写 读写 可否重复 是 是 否 是 存储方式 值 值 键(不能重复) 键值对(键不能重复) 是否有序 有序 有序 无序 无序,自动正序 初始化 [1,\'a\']
(\'a\', 1)
set([1,2])
或{1,2}
{\'a\':1,\'b\':2}
添加 append
只读 add
d[\'key\'] = \'value\'
读元素 l[2:]
t[0]
无 d[\'a\']
-
.英文词频统计实例
1.待分析字符串
2.分解提取单词
1.大小写 txt.lower()
2.分隔符\'.,:;?!-_’
3.单词列表
3.单词计数字典
music=\'\'\'When I was yong, I’d listen to the radio,Waiting for my favorite songs.When they played. I’d sing along, It made me smile. Those were such happy times, And not so long ago. How I wondered where they’d gone. But they’re back again, Just like a long lost friend. All the songs I love so well. Every sha-la-la-la ,Enery wo-wo still shines, Every shinga-linga-ling,That they’restarting to sing so fine. When they get to the part !Where he,s breaking her heart,It can really make me cry, Just like before, It’s yesterday once more. It was songs of love That I would sing to them, And I’d memorize each word, Those old melodies , Still sound so good to me, As they melt the years away.\'\'\' music=music.lower() print(music) for i in \',.\': music=music.replace(i,\'\') words=music.split(\' \') print(words) dic={} for i in words: dic[i]= music.count(i) music=list(dic.items()) print(\'单词计数字典:\',music,\'\\n\')
以上是关于组合数据类型练习,英文词频统计实例上的主要内容,如果未能解决你的问题,请参考以下文章