January 3, 2022

🧨 과제 λ‚΄μš©

**πŸ“‹ 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()`