728x90
기본 아이디어
participant - completion
주의 사항
'참가자 중에는 동명이인이 있을 수 있다'
from collections import Counter
def solution(participant, completion):
answer = Counter(participant) - Counter(completion)
return list(answer.keys())[0]
- 동명이인을 고려해야하기 때문에
set(participant) - set(completion)
을 하면 안 됨. (동명이인이 집계되지 않음) - 동명이인도 개별키로 고려하여 집계하기 위해
collections.Counter
클래스 사용 answer.keys()
는 딕셔너리 뷰이므로 인덱스 접근 불가함.list()
처리 후 첫번째 인덱스 접근하여 return
저번주 파이썬 스터디에서 공부한 딕셔너리 나왔지렁
728x90
'Programming > Python' 카테고리의 다른 글
[프로그래머스] 최소직사각형 (0) | 2025.03.27 |
---|---|
[프로그래머스] 같은 숫자는 싫어 (0) | 2025.03.26 |
[백준] 2164 | 카드2 (1) | 2024.12.11 |
[백준] 10773 | 제로 (0) | 2024.12.11 |
[백준] 1920 | 수 찾기 (0) | 2024.12.11 |