December 30, 2021

🧨 과제 내용

**📋 Entire Code**

🚝 Purpose of This Code

Yesterday 가사가 저장되어 있는 텍스트 파일을 읽어 가사에 사용되고 있는 단어들의 목록을 알파벳 순서로 출력하고, 각 단어들이 몇 개씩 사용되고 있는지 단어별 개수를 출력하는 프로그램 작성

❄ 파일 읽기

 `f1=open('yesterday.txt', 'r')`

❄ 파일의 내용 읽기

total=''

while True:
    line = f1.read()
    if not line:
        break
    strings = line.strip('\\n')
    total += (strings+' ')

❄ 단어의 갯수를 세기 위한 전처리

low_total = total.lower()

words_list=set(low_total.split())
words_list=sorted(words_list)

words=low_total.split()

❄ 단어의 갯수를 세서 출력

result = {}
for i in words_list:
    cnt= words.count(i)

    result= {i : cnt}
    print(result)

❄ 파일 닫기

 `f1.close()`