관리 메뉴

솜씨좋은장씨

[BaekJoon] 2386번 : 도비의 영어 공부 (Python) 본문

Programming/코딩 1일 1문제

[BaekJoon] 2386번 : 도비의 영어 공부 (Python)

솜씨좋은장씨 2022. 8. 1. 12:38
728x90
반응형

코딩 1일 1문제! 오늘의 문제는 백준의 도비의 영어 공부 입니다.

 

2386번: 도비의 영어 공부

출력의 각 줄은 입력으로 주어진 소문자와 그 소문자 알파벳이 나타난 횟수로 이루어진다. 이때 문장에서 해당 알파벳이 소문자로 나타나던 대문자로 나타나던 모두 세야 한다.

www.acmicpc.net

👨🏻‍💻 코드 ( Solution )

from collections import Counter


def count_word(sentence, word):
    count = 0
    
    sentence = list(sentence)
    cnt = Counter(sentence)
    
    if word in cnt:
        count = cnt[word]
        
    return count

def dobbys_english_study(study_list):
    answer_list = []
    for study in study_list:
        count = count_word(sentence=study[1], word=study[0])
        
        answer = f"{study[0]} {count}"
        
        answer_list.append(answer)
        
    return answer_list


if __name__ == "__main__":
    study_list = []
    
    while True:
        study = input()
        
        if study == "#":
            break
            
        study = study.split()
        word, sentence = study[0], " ".join(study[1:]).lower()
        study_list.append((word, sentence))
        
    answer_list = dobbys_english_study(study_list=study_list)
    
    for answer in answer_list:
        print(answer)
 

GitHub - SOMJANG/CODINGTEST_PRACTICE: 1일 1문제 since 2020.02.07

1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.

github.com

Comments