TOP

2.2 collection 模块

2.2.1 定义命名元祖

 

2.2.2 定义双端队列

2.2.3 定义有序的字典

2.2.4 定义有默认值的字典

 2.2.5 计数器

from collections import Counter

li = [2, 5, 3, 4, 1, 8, 1, 2, 6, 6, 1, 5, 1, 5]

c = Counter(li)
print(c)  # Counter({1: 4, 5: 3, 2: 2, 6: 2, 3: 1, 4: 1, 8: 1})

print(c.most_common(3))  # [(1, 4), (5, 3), (2, 2)]

 

 

 

 

 

 

 

 

 

posted @ 2019-01-30 17:25  羊驼之歌  阅读(206)  评论(0编辑  收藏  举报