DICTIONARY (2) 썸네일형 리스트형 [EP0062] 같은 숫자로 이루어진 세제곱이 다섯개 #!/usr/bin/env python # Project Euler 62 # http://projecteuler.net/index.php?section=problems&id=62 # Problem 62 # # The cube, 41063625 (3453), can be permuted to produce two other cubes: # 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest # cube which has exactly three permutations of its digits which are also # cube. # # Find the smallest cube for which exactly five permut.. [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 다음