리스트 (2) 썸네일형 리스트형 [파이썬초보] TypeError: 'NoneType' object is not subscriptable not subscriptable 은 var[ ] 와 같이 생긴 부분에서 에러가 났다는 말임. >>> a = 1 >>> b = 22.1 >>> c = 'abc' >>> c[1] 'b' >>> a[1] Traceback (most recent call last): File "", line 1, in a[1] TypeError: 'int' object is not subscriptable >>> b[1] Traceback (most recent call last): File "", line 1, in b[1] TypeError: 'float' object is not subscriptable 위 예제에서 a[1] 에서 'int' object is not subscriptable 이란 에러가 발생했다. a = .. [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 다음