practivceAlgorithm/programmers

[Programmers][Python] KAKAO 2019 오픈채팅방

findTheValue 2021. 10. 28. 20:04

dictionary로 저장해서 최후에 저장된 값으로 출력조정했습니다.

 

def solution(record):
    answer = []
    users = {}
    for log in record:
        command, *user = log.split()
        if command == 'Enter' or command == 'Change':
            user_id, nickname = user
            users[user_id] = nickname
    for log in record:
        command, *user = log.split()
        if command == 'Enter':
            user_id, nickname = user
            answer.append(f'{users[user_id]}님이 들어왔습니다.')
        elif command == 'Leave':
            answer.append(f'{users[user.pop()]}님이 나갔습니다.')

    return answer