组合数据类型和英文词频统计实例
2017-09-20 17:57
477 查看
1.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
2.字典实例:建立学生学号成绩字典,做增删改查遍历操作。
3.列表,元组,字典,集合的遍历。总结列表,元组,字典,集合的联系与区别。
列表使用方括号,元组使用小括号,字典使用花括号,集合使用[()];
元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可,列表则复杂多;
列表、字典、集合能增加、修改、删除,元组不能;
4.英文词频统计实例
>>> ls=list('1231323232323131323') >>> ls ['1', '2', '3', '1', '3', '2', '3', '2', '3', '2', '3', '2', '3', '1', '3', '1', '3', '2', '3'] >>> ls.append('4') >>> ls.append('5') >>> ls ['1', '2', '3', '1', '3', '2', '3', '2', '3', '2', '3', '2', '3', '1', '3', '1', '3', '2', '3', '4', '5'] >>> ls.pop() '5' >>> ls ['1', '2', '3', '1', '3', '2', '3', '2', '3', '2', '3', '2', '3', '1', '3', '1', '3', '2', '3', '4'] >>> ls.index('3') 2 >>> ls.count('1') 4 >>> ls.count('3') 9 >>>
2.字典实例:建立学生学号成绩字典,做增删改查遍历操作。
>>> d={'01':'95','02':'85','03':'90','04':'92','05':'72','06':'93'} >>> d.keys() dict_keys(['01', '02', '03', '04', '05', '06']) >>> d.values() dict_values(['95', '85', '90', '92', '72', '93']) >>> d.get('03','100') '90' >>> d['99']='99' >>> d {'01': '95', '02': '85', '03': '90', '04': '92', '05': '72', '06': '93', '99': '99'}
3.列表,元组,字典,集合的遍历。总结列表,元组,字典,集合的联系与区别。
>>> l=list('123456665432145') >>> t=tuple('65432566123333') >>> d={'01':'刘','02':'张','03':'王','04':'李'} >>> s=set('123654598777296582') >>> l ['1', '2', '3', '4', '5', '6', '6', '6', '5', '4', '3', '2', '1', '4', '5'] >>> >>> t ('6', '5', '4', '3', '2', '5', '6', '6', '1', '2', '3', '3', '3', '3') >>> >>> d {'01': '刘', '02': '张', '03': '王', '04': '李'} >>> >>> s {'8', '2', '7', '9', '1', '3', '6', '5', '4'} >>>
列表使用方括号,元组使用小括号,字典使用花括号,集合使用[()];
元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可,列表则复杂多;
列表、字典、集合能增加、修改、删除,元组不能;
4.英文词频统计实例
new = '''An empty street An empty house A hole inside heart all alone and the rooms Are getting smaller I wonder how I wonder why I wonder where they are The days we had The songs we sang together And oh! my love holding on forever Reaching for a love That seems so far So I say a litter prayer No my dream will take me there Where the skies are blue to see you once again my love Overseas from coast to coast Find a place I love the most Where the fields are green To see you once again My love I Try to read I go to work laughing with my friends But I can't stop to keep myself From thinking I wonder how I wonder why I wonder where they are The days we had The songs we sang togetther And oh! my love I'mholding on forever Reaching for a love That seems so far So I say a litter prayer No my dream will take me there Where the skies are blue to see you once again my love Overseas from coast to coast Find a place I love the most Where the fields are green To see you once again To hold you in my arms To promise my love To tell you from my heart You are all I'm thinking of Reaching for a love That seems so far So I say a litter prayer No my dream will take me there Where the skies are blue to see you once again my love Overseas from coast to coast Find a place I love the most Where the fields are green To see you once again My love And hope my dream will take me there Where the skies are blue to see you once again my love Overseas from coast to coast Find a place I love the most Where the fields are green To see you once again My love''' new=new.lower() for i in '.,"': new=new.replace(i,' ') word = new.split(' ') dic ={} keys = set(word) for i in keys: dic[i]=word.count(i) words = list(dic.items()) words.sort(key= lambda x:x[1],reverse = True) for i in range(10): print(word[i])
相关文章推荐
- 组合数据类型练习,英文词频统计实例
- 组合数据类型练习,英文词频统计实例
- 组合数据类型练习,英文词频统计实例
- Hadoop入门(八)自定义类型实例-统计手机流量数据Demo
- Python中的数据类型转换举例及脚本统计服务器内存实例
- 实验二-2 Eclipse&Hadoop 做英文词频统计进行集群测试
- MATLAB新的统计数据类型Table
- c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程
- HBase的java编程实例-写入词频统计
- Java操作含Clob或者NClob数据类型的存储过程实例
- 如何利用python统计英文文章词频
- 《Python3程序开发指南(第二版)》第3章 组合数据类型 练习
- XML简介Schema之XSD XSD 实例 VS 字符串数据类型
- python机器学习-数据类型统计
- 数据类型转换实例(C#)
- Hive的数据类型解析和表的操作实例
- python组合数据类型--集合
- [Python]常用的组合数据类型
- Python中的变量、数据类型(数值、列表)操作实例
- 用ruby统计英文文章的词频