SMALL
파이썬에서 딕셔너리에 원소를 추가할 때
그래프 문제에서 딕셔너리를 생성할 때 유용하다.
# dictionary
dictionary[key] = dictionary.get(key, set()).union({new_value})
dictionary[key] = (dictionary.get(key, list()) + [new_value])'Language > Python' 카테고리의 다른 글
| 6. 파이썬 input 읽기 - 백준 사이트에서 필수 사용! (0) | 2021.08.11 |
|---|---|
| 5. 파이썬 PriorityQueue vs heapq (0) | 2021.08.08 |
| 3. 파이썬 Deque 데크 자료형 (0) | 2021.07.27 |
| 2. 파이썬 딕셔너리 모듈 defaultdict, Counter (0) | 2021.07.22 |
| 1. python의 객체 - python은 모든 것이 객체다. (0) | 2021.07.06 |
댓글