[프로그래머스] 오픈채팅방

골솔·2021년 5월 12일
0

알고문제풀기

목록 보기
16/27

Lv 2 오픈채팅방

from collections import defaultdict

def solution(record):
    answer = []
    temp = []
    id = defaultdict(str)
    for rec in record:
        a = list(rec.split())
        if a[0] == "Enter":
            id[a[1]] = a[2]
            temp.append((a[1], 0))
        elif a[0] == "Leave":
            temp.append((a[1], 1))
        else : # a[0] == "Change":
            id[a[1]] = a[2]
    for t in temp:
        a, b = t[0], t[1]
        if b==0: #enter
            msg = id[a]+"님이 들어왔습니다."
        else: #leave
            msg = id[a]+"님이 나갔습니다."
        answer.append(msg)
            
    return answer
profile
골때리는이솔

0개의 댓글