immutable (1) 썸네일형 리스트형 [Python] 리스트를 딕셔너리의 키로 사용하려 하는데 에러가 발생한다. TypeError: unhashable type 리스트를 딕셔너리의 키로 사용하려 하면 에러가 발생한다. 이럴 때에는 리스트를 튜플(tuple)로 변환하면 키로 사용할 수 있다. 아래 간단한 샘플코드를 참조하면 되겠다. >>> d = {} >>> l = [1,2] >>> d[l] = 33 Traceback (most recent call last): File "", line 1, in d[l] = 33 TypeError: unhashable type: 'list' >>> d[[3,7]] = 27 Traceback (most recent call last): File "", line 1, in d[[3,7]] = 27 TypeError: unhashable type: 'list' >>> d[tuple(l)] = 33 >>> d {(1, 2): 33} >.. 이전 1 다음