Programming/Python

[프로그래머스] 완주하지 못한 선수

왕밤빵도라에몽 2025. 3. 26. 10:23
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