2.2.1 定义命名元祖

2.2 collection 模块

 2.2 collection 模块

2.2.2 定义双端队列

2.2 collection 模块

2.2 collection 模块

2.2.3 定义有序的字典

2.2 collection 模块

2.2.4 定义有默认值的字典

2.2 collection 模块

 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)]

 

 

 

 

 

 

 

 

 

相关文章:

  • 2021-04-13
  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
  • 2021-06-25
  • 2021-12-04
  • 2021-09-02
  • 2021-05-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-04-19
  • 2021-10-21
  • 2022-12-23
  • 2021-10-29
相关资源
相似解决方案