input
id_list, report, k
output
중복을 제외하고 신고를 k 번 이상받은 id에 대해서, 몇 번의 신고통지를 받는지 list로 출력
k번 이상 신고당한 id를 리스트에 넣고 해당 리스트를 신고한 id 신고통지 몇 번 받는지 for문과 if문 사용
-> runtime error
나의 풀이
def solution(id_list, report, k): answer = [] temp = [] y = [] x = [] # 중복제거 report2 = list(set(report)) # report2에서 신고당한 사람 temp에 저장 for i in report2: temp.append(i.split()[1]) if temp.count(i.split()[1]) == k: y.append(i.split()[1]) for i in report2: if i.split()[1] in y: x.append(i.split()[0]) for i in id_list: if i in x: answer.append(x.count(i)) else: answer.append(0) return answer
모범코드
def solution(id_list, report, k): answer = [0] * len(id_list) dic_report = {id: [] for id in id_list} # 해당 유저를 신고한 ID for i in set(report): i = i.split() dic_report[i[1]].append(i[0]) for key, value in dic_report.items(): if len(value) >= k: for j in value: answer[id_list.index(j)] += 1 return answer
반성)