Python数组统计排序问题
2017-10-05 11:46
302 查看
这里使用Counter这个类,很容易,只要采用使用lambda函数,很容易解决
from collections import Counter times_intervals = [1,2,3,4,5,5,6,6] times_count = Counter(times_intervals) print times_count times_sorted = sorted(times_count.items(), key=lambda x:x[0]) print times_sorted print [t[0] for t in times_sorted] >>> Counter({5: 2, 6: 2, 1: 1, 2: 1, 3: 1, 4: 1}) [(1, 1), (2, 1), (3, 1), (4, 1), (5, 2), (6, 2)] [1, 2, 3, 4, 5, 6]
相关文章推荐
- python 统计数组中元素出现次数并进行排序
- Python之Matplotlib 解决绘图 X 轴值不按数组排序问题.
- python 统计数组中元素出现次数并进行排序的实例
- Python numpy数组排序问题
- python学习笔记:二维数组排序问题
- python统计数组元素出现次数以及排序
- python:numpy数组运算、排序、统计、随机数生成
- JNI之c/c++返回中文给java 乱码问题以及java数组在c排序
- python list 中元素的统计与排序
- python已字典为元素的数组排序
- PHP 字符串数组按照拼音排序的问题
- [ mathematica 进阶问题 ] 怎么样对含有变量的数组进行排序?
- 统计一个数字在排序数组中出现的次数
- 数组元素排序问题!
- 统计一个数字在排序数组中出现的次数
- python中文字符串数组编码的问题
- python笔记之:两个数组同时排序
- 某面试题--数组排序问题
- Python数组排序
- python 多维数组构建问题