⚡️algorithm/step-up ++
[Dictionary 탐색] 프로그래머스 lv2. 신고결과받기 (feat. enumerate, set, dictionary)
남남이루
2022. 9. 8. 18:19
[ 문제 바로가기 ]
수도코드
내 답안
def solution(users, report, k):
report = set(report)
report = [text.split() for text in report]
history = {x[0]:[] for x in report}
reported_cnt = {key:0 for key in users}
reported_who = {key:[] for key in users}
# block
for content in report:
whom = content[1]
reported_cnt[whom] += 1
reported_who[whom].append(content[0])
blocked = [i for i, cnt in reported_cnt.items() if cnt >= k]
result = [0] * len(users)
for whom in blocked:
multi_who = reported_who[whom]
for who in multi_who:
result[users.index(who)] +=1
return result
관련 개념과 활용
자료형 순회할 때 필수적으로 사용되는 메서드
- enumerate()
list의 idx, value 순회할 때 사용 - .items()
dictionary 키값 순회할 때 사용 - set()
set([list형]) => set형 1차 depth로 반환됨