Python/프로그래머스

[LV1] 신고 결과 받기 - 2022 KAKAO BLIND RECRUITMENT

헬로희 2024. 11. 29. 22:46
728x90

Q. 유저(id_list)가 불량 이용자를 신고하고 k번 이상 신고이력이 있는 경우에만 신고처리결과를 통보 받음.
각 유저가 신고처리 결과를 통보받을 횟수는?

  • report = ["신고유저 신고당한유저", "신고유저 신고당한유저" , ...]
  • 신고 횟수에 제한은 없으나 신고 횟수는 1회로 처리
  • k번 이상 신고된 유저는 이용 정지

 

def solution(id_list, report, k):
    report = list(set(report))
    id_dict = {}
    for id in id_list:
        id_dict[id] = 0

    result = id_dict.copy()
    for re in report:
        id_dict[re.split(" ")[1]] += 1
    
    name = [key for key, val in id_dict.items() if val >= k ]
    for re2 in report:
        if re2.split(" ")[1] in name:
            result[re2.split(" ")[0]] += 1
    return list(result.values())

 

728x90