Python 标准库中的容器

namedtuple

a class template to generated memory efficient class

MyClass = namedtuple('MyClass', [attrib_foo, attrib_bar, ...])

keys and items of a dict can be used as a set.

deque

deque is implemented as deque, it can be created with maxlen=N

appendleft, popleft, append, pop

defaultdict

multidict = defaultdict(list) # builds a multidict using list
multidict = defaultdict(set) # builds a multidict using set

OrderedDict

it perserves the order as insertion, implemented with a linked list

Counter

words_count = Counter(words)

Counter.most_common(N) returns tuple
Counter.update(more) add more words

counter even supports +/-

及时获取更新,请关注公众号“爬虫技术学习(spider-learn)”

公众号“爬虫技术学习(spider-learn)”

About 逸飞

后端工程师

发表评论

电子邮件地址不会被公开。 必填项已用*标注