collections模块简介
1.collections模块
在内置数据类型(dict、list、set、tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter、deque、defaultdict、namedtuple等。
1.1 Counter
计数器,主要用来记录每一个元素出现的次数
可以用来统计单词出现的次数
import collections
# 统计text_list中单词出现的次数
text_list = ['this', 'isn', 'to', 'be', 'out', 'that', 'has', 'in', 'the', 'past', 'the', 'didn', 'go', 'so', 'well', 'for', 'jobs', 'were', 'by', 'but', 'it', 'and', 'more', 'jobs', 'than', 'it', 'by', 'down', 'and', 'free', 'from', 'hard', 'work', 'but', 'in', 'the', 'term', 'may', 'need'<