collections
Stdlib — DataPython 2.0+Intermediate
Specialized containers: deque, Counter, defaultdict, OrderedDict, ChainMap, namedtuple
Quick Info
- Documentation
- Official Docs
- Python Version
- 2.0+
- Dependencies
- None — Python Standard Library
- Install
Included with Python
Learn by Difficulty
Quick Example
python
from collections import Counter, defaultdict # Counter words = ["apple", "banana", "apple", "cherry", "banana", "apple"] c = Counter(words) print(c) print(c.most_common(2)) # defaultdict dd = defaultdict(list) dd["fruits"].append("apple") dd["fruits"].append("banana") print(dict(dd))
The collections module is part of Python's standard library. Specialized containers: deque, Counter, defaultdict, OrderedDict, ChainMap, namedtuple.
Try in PlaygroundTags
stdlibdata-structurecontainerdatatype