Python 利用字典计算数据中不重复的数量
2018-03-22 14:58
447 查看
因为字典的键必须是唯一的,那么将数据作为键值,那么键的数量就是不重复的数量
输出:
datas = "x1 x2 x2 x3 x4 x5 x6 x7 x7 x8 x9" for data in datas.split(): print(data) dict = {data: None for data in datas.split()}#data为键,None为键对应的值(任意值) print("dict=",dict) print("不重复的长度:",len(dict))
输出:
x1 x2 x2 x3 x4 x5 x6 x7 x7 x8 x9 dict= {'x1': None, 'x7': None, 'x4': None, 'x9': None, 'x6': None, 'x2': None, 'x5': None, 'x8': None, 'x3': None} 不重复的长度: 9
相关文章推荐
- Python利用pandas计算多个CSV文件数据值的实例
- 利用python对中文文本数据进行LDA训练、计算概率距离
- 利用mapreduce计算框架向hbase插入数据(python脚本)
- 【利用Python进行数据分析——经验篇2】计算微博转发/评论/点赞h指数的Python代码
- 利用Python进行数据分析(9) pandas基础: 汇总统计和计算
- 大数据日志分析系统-python脚本利用es聚合计算
- 利用 Python 进行数据分析(九)pandas 汇总统计和计算
- 利用Python进行数据分析(6) NumPy基础: 矢量计算
- 如何利用bash/python计算IP子网容纳计算机数量
- Python利用pandas计算多个CSV文件数据值
- 利用python统计车数量及重复车牌号
- Python多维/嵌套字典数据无限遍历
- 利用python进行数据分析-绘图和可视化2
- 利用awk计算文件的单词数量及排序
- 利用Python内置函数计算当前时间
- 深入学习Python内置数据类型之——字典(Dictionary)
- 去除字符串重复数据 分类: python基础学习 2013-08-08 17:43 171人阅读 评论(0) 收藏
- Python利用字典实现switch功能
- 用户如何有效地利用数据字典
- 利用row_number函数处理重复数据