오늘의 에러 : TypeError: unhashable type: 'list' 발생 원인 : dictionary 의 key를 접근할 때, list를 넣었기 때문 해결 방안 : list type을 int type으로 변경해준다. # dictionary a = {0:0, 1:0} result = [1] a[result] += 1 위와 같이 코딩하게 된다면, 위에서 나온 에러(TypeError: unhashable type: 'list')를 만날 수 있다. 왜냐하면, 사실상 a[result]에서 요청하는 값이 a[[1]] 이런 모양이기 때문이다.
따라서 이를 해결하기 위해서는 a[1]과 같이 접근해야하고, 그럼 int type으로 변환이 필요하다. 1. indexing a[result[0]] += 1 2. str to int b = [str(i) for i in result] b = ''.join(b) a[int(b)] += 1 개인적으로는 1의 방법을 추천한다....
#
dictionary
#
list
#
python