python list to dictionary key 파이썬에서 list의 항목들을 dictionary 의 key로 변환하는 가장 빠른 방법은 fromkeys 함수를 사용하는 것 일것이다. 사용 예제는 다음과 같다. category_per_sent = dict.fromkeys([2,3,4], list()) print(category_per_sent) [2, 3, 4]를 dictionary key로 변환해주고, 그 value에는 빈 list를 넣어줬다. print의 결과는 다음과 같다. {2: [], 3: [], 4: []} 여기까지는 잘 된것 처럼 보인다.
그럼 이제 value에 있는 list에 값을 하나 추가해보자. category_per_sent[2] += [1] print(category_per_sent) 이때 우리가 바라는 결과값은 아래 표와 같을 것이다. KEY Value 2 [1] 3 [] 4 [] print를 찍어보자 print(category_per_sent) # {2...
#
dictionary
#
for
#
fromkeys
#
key
#
list
#
loop
#
python
#
to