Dictionary는 Hash Table로 구성되어 있는데, 이는 상수 시간으로 접근이 가능하다.
Counter의 연산. Counter는 Dictionary의 subclass이다.
>>> c = Counter(a=3, b=1)
>>> d = Counter(a=1, b=2)
>>> c + d # add two counters together: c[x] + d[x]
Counter({'a': 4, 'b': 3})
>>> c - d # subtract (keeping only positive counts)
Counter({'a': 2})
>>> c & d # intersection: min(c[x], d[x])
Counter({'a': 1, 'b': 1})
>>> c | d # union: max(c[x], d[x])
Counter({'a': 3, 'b': 2})
>>> c == d # equality: c[x] == d[x]
False
>>> c <= d # inclusion: c[x] <= d[x]
False
collections — Container datatypes — Python 3.10.2 documentation
collections — Container datatypes Source code: Lib/collections/__init__.py This module implements specialized container datatypes providing alternatives to Python’s general purpose built-in containers, dict, list, set, and tuple. namedtuple() factory f
docs.python.org
'Coding Test > 정리' 카테고리의 다른 글
[Swift] Swift를 이용한 문제 풀이 (0) | 2022.06.15 |
---|---|
[python] list pop VS pop first (0) | 2022.03.08 |
[python] functools.cmp_to_key(func) (0) | 2022.02.22 |