def solution(id_list, report, k):
hack = {id: [] for id in id_list}
for case in report:
a, b = case.split(' ')
if a not in hack[b]:
hack[b].append(a)
result = [0] * len(id_list)
for idx, user in enumerate(id_list):
for reported_users in hack.values():
if user in reported_users and len(reported_users) >= k:
result[idx] += 1
print(result)
return result
id_list = ["muzi", "frodo", "apeach", "neo"]
report = ["muzi frodo", "apeach frodo", "frodo neo", "muzi neo", "apeach muzi"]
k = 2
print(solution(id_list, report, k))
IDE에서 푸느라 id_list, report, k를 제거하지 않고 제출했는데 통과되긴 한다..
def solution(id_list, report, k):
hack = {id: [] for id in id_list}
for case in report:
a, b = case.split(' ')
if a not in hack[b]:
hack[b].append(a)
result = [0] * len(id_list)
for idx, user in enumerate(id_list):
for reported_users in hack.values():
if user in reported_users and len(reported_users) >= k:
result[idx] += 1
return result