defaultdict

Algorithm/Python

파이썬 defaultdcit 런타임에러 RuntimeError: dictionary changed size during iteration

from collections import defaultdict graph = defaultdict(list) for x in graph: ... 런타임 에러 발생 원인: defaultdict는 존재하지 않는 키 조회 시 오류가 생기지 않게 하기 위해 항상 디폴트를 생성함. from collections import defaultdict graph = defaultdict(list) for x in list(graph): ... 해결 방법: 새로운 복사본 생성 graph -> list(graph)

박한결
'defaultdict' 태그의 글 목록