Skip to content
UPEEC

collections

Specialised containers: Counter, defaultdict, deque, namedtuple, OrderedDict and ChainMap.

Easy
Comments 0
from collections import Counter, defaultdict, deque, namedtuple
Counter("mississippi").most_common(2)   # [('i', 4), ('s', 4)]
groups = defaultdict(list); groups["R"].append("R1")
q = deque(maxlen=100)                   # ring buffer of recent samples
Point = namedtuple("Point", "x y")

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.