collections在python官方文档中的解释是High-performance container datatypes,直接的中文翻译解释高性能容量数据类型。
它总共包含五种数据类型。
其中Counter中文意思是计数器,也就是我们常用于统计的一种数据类型,在使用Counter之后可以让我们的代码更加简单易读。
>>> from collections import Counter
>>> colors = ['red', 'blue', 'red', 'green', 'blue', 'blue']
>>> c = Counter(colors)
>>> c
Counter({'blue': 3, 'red': 2, 'green': 1})