컴공생의 다이어리

[프로그래머스] 오픈채팅방 - 파이썬(Python) 본문

Development/Algorithm & Coding Test

[프로그래머스] 오픈채팅방 - 파이썬(Python)

컴공 K 2022. 6. 11. 00:01

[프로그래머스] 오픈채팅방 - 파이썬(Python)

 

 

 

def solution(record):
    answer = []
    id_dict = dict()  # id에 해당하는 이름 정보
    commands = [list(r.split()) for r in record]  # record의 데이터들을 공백 기준으로 분리

    for command in commands:
        if command[0] == 'Enter' or command[0] == 'Change':  # id에 해당하는 닉네임 정보 생성 혹은 업데이트
            id_dict[command[1]] = command[2]

    for command in commands:
        if command[0] == 'Enter':
            answer.append(id_dict[command[1]] + "님이 들어왔습니다.")
        elif command[0] == 'Leave':
            answer.append(id_dict[command[1]] + "님이 나갔습니다.")
    return answer

 

 

 

 

https://programmers.co.kr/learn/courses/30/lessons/42888

 

코딩테스트 연습 - 오픈채팅방

오픈채팅방 카카오톡 오픈채팅방에서는 친구가 아닌 사람들과 대화를 할 수 있는데, 본래 닉네임이 아닌 가상의 닉네임을 사용하여 채팅방에 들어갈 수 있다. 신입사원인 김크루는 카카오톡 오

programmers.co.kr

 

728x90
Comments