본문 바로가기
Language/Python

4. 딕셔너리 key에 value추가하기

by 규나 2021. 8. 5.
SMALL

파이썬에서 딕셔너리에 원소를 추가할 때

그래프 문제에서 딕셔너리를 생성할 때 유용하다.

# dictionary

dictionary[key] = dictionary.get(key, set()).union({new_value})
dictionary[key] = (dictionary.get(key, list()) + [new_value])

댓글