728x90
https://school.programmers.co.kr/learn/courses/30/lessons/92334
from collections import defaultdict
from collections import OrderedDict
def solution(id_list, report, k):
answer = []
id_dict = OrderedDict()
count = defaultdict(int)
for id in id_list:
id_dict[id] = []
for data in report:
a, b = data.split()
if b not in id_dict[a]:
id_dict[a].append(b)
else:
continue
for data in id_dict.values():
if data:
for id in data:
count[id] += 1
out = []
for key, value in count.items():
if value >= k:
out.append(key)
for key, value in id_dict.items():
temp = 0
for id in out:
if id in value:
temp += 1
answer.append(temp)
return answer
728x90
'Algorithm (PS)' 카테고리의 다른 글
[백준] 20207 달력 Python (0) | 2022.10.01 |
---|---|
[백준] 17836 공주님을 구해라 ! Python (0) | 2022.09.29 |
[백준] 20056 마법사 상어와 파이어볼 Python (0) | 2022.09.28 |
[정보처리기사/실기] 웹 서버(Web Server)의 기능 (0) | 2022.09.27 |
[카카오] 양궁대회 Python/BFS (0) | 2022.09.27 |