최대 1 분 소요

:fire: 문제 이해

  1. 퇴장, 입장, 변동 3가지의 사용자 행동
  2. 사용자 구분은 uuid를 통한 수행
  3. 사용자 이름은 변경 될 수 있음
  4. 변경된 최종 이름으로 3가지 사용자 행동에 대한 리스트 반환

:speech_balloon: 로직

  1. 사용자 행동을 UUID + 행동 형식으로 리스트 생성
  2. UUID와 사용자 이름을 맵핑해서 최종 맵핑 데이터 생성
  3. 1번에서 생성된 리스트 내 UUID를 사용자 최종 이름으로 변경

:speech_balloon: 코드

def solution(record):
    uuidName = dict()
    answer = []
    actionList = list()
    
    for data in record:
        dataList = data.split(" ")
        if dataList[0] == "Leave":
            actionList.append([dataList[1], "님이 나갔습니다."])
        elif dataList[0] == "Enter":
            uuidName[dataList[1]] = dataList[2]
            actionList.append([dataList[1], "님이 들어왔습니다."])
        elif dataList[0] == "Change":
            uuidName[dataList[1]] = dataList[2]
        else:
            print("Value Error")

    for action in actionList:
        answer.append(uuidName[action[0]] + action[1])
    return answer

:memo: 결론

  1. 딕셔너리에 익숙하지 않을 때, 단순 문자열 비교로 처리하려고 시도
    • 해당 방법은 속도도 느리고, 반례 존재(케이스에 uuid45, uuid456 존재 시)
  2. 딕셔너리를 통해 Name의 중복을 제거하고, 최신 Name 데이터만 들고 있음
  3. 파이썬 자료구조에 빨리 익숙해지자…