[Python] 연습

[python] 프로그래머스 신고결과받기

Simon Yoon 2022. 10. 29. 21:45
def solution(id_list, report ,k):
    answer = []

    # id_dict, reporter 생성
    id_dict = dict()
    for user in id_list:
        id_dict[user] = 0
    reporter = id_dict.copy()

    # report 중복 제거
    report = set(report)

    # count reported times
    for case in report:
        id_dict[case.split(' ')[1]] += 1
    print(id_dict)  # id_dict는 각 회원이 신고받은 횟수

    # count messages to reporter
    for case in report:
        if id_dict[case.split(' ')[1]] >= k:
            reporter[case.split(' ')[0]] += 1
    print(reporter)
    print(list(reporter.values()))

    return list(reporter.values())