这里使用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]