Python빈칸 채우기보통 · 20점#딕셔너리#반복문

15. 딕셔너리 get으로 단어 빈도 세기

다음은 단어의 등장 횟수를 딕셔너리로 세는 Python 프로그램이다. 실행 결과가 "{'apple': 3, 'kiwi': 2, 'plum': 1}", "27", "apple -1" 세 줄이 되도록 빈칸 ①에 들어갈 값과 빈칸 ②에 들어갈 메서드 이름을 쓰시오.

1words = ["apple", "kiwi", "apple", "plum", "kiwi", "apple"]
2count = {}
3for w in words:
4 count[w] = count.get(w, ( ① )) + 1
5print(count)
6total = 0
7for key in count:
8 total += len(key) * count[key]
9print(total)
10best = ""
11for key, value in count.( ② )():
12 if value > count.get(best, 0):
13 best = key
14print(best, count.get("pear", -1))

해설을 먼저 보면 이후 정답 시 점수가 50%만 반영됩니다.